1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
|
.\" Copyright (c) 1994,1995 Mike Battersby <mib@deakin.edu.au>
.\" based on work by faith@cs.unc.edu
.\"
.\" Permission is granted to make and distribute verbatim copies of this
.\" manual provided the copyright notice and this permission notice are
.\" preserved on all copies.
.\"
.\" Permission is granted to copy and distribute modified versions of this
.\" manual under the conditions for verbatim copying, provided that the
.\" entire resulting derived work is distributed under the terms of a
.\" permission notice identical to this one
.\"
.\" Since the Linux kernel and libraries are constantly changing, this
.\" manual page may be incorrect or out-of-date. The author(s) assume no
.\" responsibility for errors or omissions, or for damages resulting from
.\" the use of the information contained herein. The author(s) may not
.\" have taken the same level of care in the production of this manual,
.\" which is licensed free of charge, as they might when working
.\" professionally.
.\"
.\" Formatted or processed versions of this manual, if unaccompanied by
.\" the source, must acknowledge the copyright and authors of this work.
.\"
.\" Modified, aeb, 960424
.\" Modified Fri Jan 31 17:31:20 1997 by Eric S. Raymond <esr@thyrsus.com>
.\" Modified Thu Nov 26 02:12:45 1998 by aeb - add SIGCHLD stuff.
.\"
.TH SIGACTION 2 "24 August 1995" "Linux 1.3" "Linux Programmer's Manual"
.SH NAME
sigaction, sigprocmask, sigpending, sigsuspend \- POSIX signal handling
functions.
.SH SYNOPSIS
.B #include <signal.h>
.sp 2
.BI "int sigaction(int " signum ", const struct sigaction *" act ","
.BI "struct sigaction *" oldact );
.sp
.BI "int sigprocmask(int " how ", const sigset_t *" set ", "
.BI "sigset_t *" oldset );
.sp
.BI "int sigpending(sigset_t *" set );
.sp
.BI "int sigsuspend(const sigset_t *" mask );
.SH DESCRIPTION
The
.B sigaction
system call is used to change the action taken by a process on
receipt of a specific signal.
.PP
.I signum
specifies the signal and can be any valid signal except
.B SIGKILL
and
.BR SIGSTOP .
.PP
If
.I act
is non\-null, the new action for signal
.I signum
is installed from
.IR act .
If
.I oldact
is non\-null, the previous action is saved in
.IR oldact .
.PP
The
.B sigaction
structure is defined as
.sp
.RS
.nf
struct sigaction {
void (*sa_handler)(int);
sigset_t sa_mask;
int sa_flags;
void (*sa_restorer)(void);
}
.fi
.RE
.PP
.I sa_handler
specifies the action to be associated with
.I signum
and may be
.B SIG_DFL
for the default action,
.B SIG_IGN
to ignore this signal, or a pointer to a signal handling function.
.PP
.I sa_mask
gives a mask of signals which should be blocked during execution of
the signal handler. In addition, the signal which triggered the handler
will be blocked, unless the
.B SA_NODEFER
or
.B SA_NOMASK
flags are used.
.PP
.I sa_flags
specifies a set of flags which modify the behaviour of the signal handling
process. It is formed by the bitwise OR of zero or more of the following:
.RS
.TP
.B SA_NOCLDSTOP
If
.I signum
is
.BR SIGCHLD ", "
do not receive notification when child processes stop (i.e., when child
processes receive one of
.BR SIGSTOP ", " SIGTSTP ", " SIGTTIN
or
.BR SIGTTOU ")."
.TP
.BR SA_ONESHOT " or " SA_RESETHAND
Restore the signal action to the default state once the signal handler
has been called. (This is the default behavior of the
.BR signal (2)
system call.)
.TP
.B SA_RESTART
Provide behaviour compatible with BSD signal semantics by making certain
system calls restartable across signals.
.TP
.BR SA_NOMASK " or " SA_NODEFER
Do not prevent the signal from being received from within its own signal
handler.
.RE
.PP
The
.I sa_restorer
element is obsolete and should not be used.
.PP
The
.B sigprocmask
call is used to change the list of currently blocked signals. The
behaviour of the call is dependent on the value of
.IR how ,
as follows.
.RS
.TP
.B SIG_BLOCK
The set of blocked signals is the union of the current set and the
.I set
argument.
.TP
.B SIG_UNBLOCK
The signals in
.I set
are removed from the current set of blocked signals. It is legal to
attempt to unblock a signal which is not blocked.
.TP
.B SIG_SETMASK
The set of blocked signals is set to the argument
.IR set .
.RE
.PP
If
.I oldset
is non\-null, the previous value of the signal mask is stored in
.IR oldset .
.PP
The
.B sigpending
call allows the examination of pending signals (ones which have been
raised while blocked). The signal mask of pending signals is stored
in
.IR set .
.PP
The
.B sigsuspend
call temporarily replaces the signal mask for the process with that
given by
.I mask
and then suspends the process until a signal is received.
.SH "RETURN VALUES"
.BR sigaction ,
.BR sigprocmask ,
.B sigpending
and
.B sigsuspend
return 0 on success and -1 on error.
.SH ERRORS
.TP
.B EINVAL
An invalid signal was specified. This will also be generated if an attempt
is made to change the action for
.BR SIGKILL " or " SIGSTOP ", "
which cannot be caught.
.TP
.B EFAULT
.IR act ", " oldact ", " set
or
.I oldset
point to memory which is not a valid part of the process address space.
.TP
.B EINTR
System call was interrupted.
.SH NOTES
It is not possible to block
.BR SIGKILL " or " SIGSTOP
with the sigprocmask call. Attempts to do so will be silently ignored.
.PP
According to POSIX, the behaviour of a process is undefined after it
ignores a SIGFPE, SIGILL, or SIGSEGV signal that was not generated
by the \fIkill()\fP or the \fIraise()\fP functions.
Integer division by zero has undefined result.
On some architectures it will generate a SIGFPE signal.
(Also dividing the most negative integer by \-1 may generate SIGFPE.)
Ignoring this signal might lead to an endless loop.
.PP
POSIX (B.3.3.1.3) disallows setting the action for SIGCHLD to SIG_IGN.
The BSD and SYSV behaviours differ, causing BSD software
that sets the action for SIGCHLD to SIG_IGN to fail on Linux.
.PP
The POSIX spec only defines
.BR SA_NOCLDSTOP .
Use of other
.I sa_flags
is non\-portable.
.PP
The
.B SA_RESETHAND
flag is compatible with the SVr4 flag of the same name.
.PP
The
.B SA_NODEFER
flag is compatible with the SVr4 flag of the same name under kernels
1.3.9 and newer. On older kernels the Linux implementation
allowed the receipt of any signal, not just the one we are installing
(effectively overriding any
.I sa_mask
settings).
.PP
The
.BR SA_RESETHAND " and " SA_NODEFER
names for SVr4 compatibility are present only in library versions 3.0.9
and greater.
.PP
.B sigaction
can be called with a null second argument to query the current signal
handler. It can also be used to check whether a given signal is valid for
the current machine by calling it with null second and third arguments.
.PP
See
.BR sigsetops (3)
for details on manipulating signal sets.
.SH "CONFORMING TO"
POSIX, SVr4. SVr4 does not document the EINTR condition.
.SH "SEE ALSO"
.BR kill "(1), " kill "(2), " killpg "(2), " pause "(2), " raise "(3), "
.BR siginterrupt "(3), " signal "(2), " signal "(7), " sigsetops "(3), "
.BR sigvec (2)
|