Penguin
Blame: sigaction(2)
EditPageHistoryDiffInfoLikePages
Annotated edit history of sigaction(2) version 5, including all changes. View license author blame.
Rev Author # Line
5 JohnMcPherson 1 !!NAME
2 sigaction, sigprocmask, sigpending, sigsuspend - [POSIX] signal handling functions.
2 PerryLorier 3
1 perry 4 !!SYNOPSIS
5 JohnMcPherson 5 __#include <signal.h>__
1 perry 6
5 JohnMcPherson 7 __int sigaction(int __ ''signum'' __, const struct sigaction *__ ''act'' __,__ __struct sigaction *__ ''oldact'' __);__
1 perry 8
5 JohnMcPherson 9 __int sigprocmask(int __ ''how'' __, const sigset_t *__ ''set'' __, __ __sigset_t *__ ''oldset'' __);__
1 perry 10
5 JohnMcPherson 11 __int sigpending(sigset_t *__ ''set'' __);__
1 perry 12
5 JohnMcPherson 13 __int sigsuspend(const sigset_t *__ ''mask'' __);__
1 perry 14
15 !!DESCRIPTION
2 PerryLorier 16 The __sigaction__ system call is used to change the action taken by a process on receipt of a specific signal.
1 perry 17
5 JohnMcPherson 18 ''signum'' specifies the signal and can be any valid signal except __SIGKILL__ and __SIGSTOP__ .
1 perry 19
5 JohnMcPherson 20 If ''act'' is non-null, the new action for signal ''signum'' is installed from ''act'' . If ''oldact'' is non-null, the previous action is saved in ''oldact'' .
1 perry 21
3 PerryLorier 22 The __sigaction__ structure is defined as something like
5 JohnMcPherson 23
24
1 perry 25
3 PerryLorier 26 struct sigaction {
5 JohnMcPherson 27 void (*sa_handler)(int);
28 void (*sa_sigaction)(int, siginfo_t *, void *);
29 sigset_t sa_mask;
30 int sa_flags;
31 void (*sa_restorer)(void);
3 PerryLorier 32 }
1 perry 33
3 PerryLorier 34
35
36
5 JohnMcPherson 37 On some architectures a union is involved - do not assign to both ''sa_handler'' and ''sa_sigaction'' .
1 perry 38
5 JohnMcPherson 39 The ''sa_restorer'' element is obsolete and should not be used. [POSIX] does not specify a ''sa_restorer'' element.
1 perry 40
5 JohnMcPherson 41 ''sa_handler'' specifies the action to be associated with ''signum'' and may be __SIG_DFL__ for the default action, __SIG_IGN__ to ignore this signal, or a pointer to a signal handling function.
1 perry 42
5 JohnMcPherson 43 ''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 __SA_NODEFER__ or __SA_NOMASK__ flags are used.
1 perry 44
5 JohnMcPherson 45 ''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:
1 perry 46
5 JohnMcPherson 47 ;__SA_NOCLDSTOP__ : If ''signum'' is [SIGCHLD] , do not receive notification when child processes stop (i.e., when child processes receive one of [SIGSTOP] , [SIGTSTP] , [SIGTTIN] or [SIGTTOU] ).
48 ;__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 signal(2) system call.)
49 ;__SA_RESTART__ : Provide behaviour compatible with BSD signal semantics by making certain system calls restartable across signals.
50 ;__SA_NOMASK__ or __SA_NODEFER__ : Do not prevent the signal from being received from within its own signal handler.
51 ;__SA_SIGINFO__ : The signal handler takes 3 arguments, not one. In this case, ''sa_sigaction'' should be set instead of ''sa_handler'' . (The sa_sigaction field was added in Linux 2.1.86.)
1 perry 52
3 PerryLorier 53
54 The ''siginfo_t'' parameter to ''sa_sigaction'' is a struct with the following elements
5 JohnMcPherson 55
56
1 perry 57
3 PerryLorier 58 siginfo_t {
5 JohnMcPherson 59 int si_signo; /* Signal number */
60 int si_errno; /* An errno value */
61 int si_code; /* Signal code */
62 pid_t si_pid; /* Sending process ID */
63 uid_t si_uid; /* Real user ID of sending process */
64 int si_status; /* Exit value or signal */
65 clock_t si_utime; /* User time consumed */
66 clock_t si_stime; /* System time consumed */
67 sigval_t si_value; /* Signal value */
68 int si_int; /* POSIX.1b signal */
69 void * si_ptr; /* POSIX.1b signal */
70 void * si_addr; /* Memory location which caused fault */
71 int si_band; /* Band event */
72 int si_fd; /* File descriptor */
3 PerryLorier 73 }
1 perry 74
3 PerryLorier 75
76
1 perry 77
5 JohnMcPherson 78 ''si_signo'' , ''si_errno'' and ''si_code'' are defined for all signals. The rest of the struct may be a union, so that one should only read the fields that are meaningful for the given signal. kill(2), POSIX.1b signals and SIGCHLD fill in ''si_pid'' and ''si_uid'' . SIGCHLD also fills in ''si_status'' , ''si_utime'' and ''si_stime'' . ''si_int'' and ''si_ptr'' are specified by the sender of the POSIX.1b signal. SIGILL, SIGFPE, SIGSEGV and SIGBUS fill in ''si_addr'' with the address of the fault. SIGPOLL fills in ''si_band'' and ''si_fd'' .
1 perry 79
5 JohnMcPherson 80 ''si_code'' indicates why this signal was sent. It is a value, not a bitmask. The values which are possible for any signal are listed in this table:
1 perry 81
5 JohnMcPherson 82 ||^__si_code__
83 |Value|Signal origin
84 |SI_USER|kill, sigsend or raise
85 |SI_KERNEL|The kernel
86 |SI_QUEUE|sigqueue
87 |SI_TIMER|timer expired
88 |SI_MESGQ|mesq state changed
89 |SI_ASYNCIO|AIO completed
90 |SI_SIGIO|queued SIGIO
1 perry 91
3 PerryLorier 92
5 JohnMcPherson 93 ||^SIGILL
94 |ILL_ILLOPC|illegal opcode
95 |ILL_ILLOPN|illegal operand
96 |ILL_ILLADR|illegal addressing mode
97 |ILL_ILLTRP|illegal trap
98 |ILL_PRVOPC|privileged opcode
99 |ILL_PRVREG|privileged register
100 |ILL_COPROC|coprocessor error
101 |ILL_BADSTK|internal stack error
102
103
104
105
106 ||^SIGFPE
107 |FPE_INTDIV|integer divide by zero
108 |FPE_INTOVF|integer overflow
109 |FPE_FLTDIV|floating point divide by zero
110 |FPE_FLTOVF|floating point overflow
111 |FPE_FLTUND|floating point underflow
112 |FPE_FLTRES|floating point inexact result
113 |FPE_FLTINV|floating point invalid operation
114 |FPE_FLTSUB|subscript out of range
115
116
117
118
119 ||^SIGSEGV
120 |SEGV_MAPERR|address not mapped to object
121 |SEGV_ACCERR|invalid permissions for mapped object
122
123
124
125
126 ||^SIGBUS
127 |BUS_ADRALN|invalid address alignment
128 |BUS_ADRERR|non-existant physical address
129 |BUS_OBJERR|object specific hardware error
130
131
132
133
134 ||^SIGTRAP
135 |TRAP_BRKPT|process breakpoint
136 |TRAP_TRACE|process trace trap
137
138
139
140
141 ||^SIGCHLD
142 |CLD_EXITED|child has exited
143 |CLD_KILLED|child was killed
144 |CLD_DUMPED|child terminated abnormally
145 |CLD_TRAPPED|traced child has trapped
146 |CLD_STOPPED|child has stopped
147 |CLD_CONTINUED|stopped child has continued
148
149
150
151
152 ||^SIGPOLL
153 |POLL_IN|data input available
154 |POLL_OUT|output buffers available
155 |POLL_MSG|input message available
156 |POLL_ERR|i/o error
157 |POLL_PRI|high priority input available
158 |POLL_HUP|device disconnected
159
160
161
162 The __sigprocmask__ call is used to change the list of currently blocked signals. The behaviour of the call is dependent on the value of ''how'' , as follows.
163
164 ;__SIG_BLOCK__ : The set of blocked signals is the union of the current set and the ''set'' argument.
165 ;__SIG_UNBLOCK__ : The signals in ''set'' are removed from the current set of blocked signals. It is legal to attempt to unblock a signal which is not blocked.
166 ;__SIG_SETMASK__ : The set of blocked signals is set to the argument ''set'' .
167
168
169 If ''oldset'' is non-null, the previous value of the signal mask is stored in ''oldset'' .
170
171 The __sigpending__ call allows the examination of pending signals (ones which have been raised while blocked). The signal mask of pending signals is stored in ''set'' .
172
173 The __sigsuspend__ call temporarily replaces the signal mask for the process with that given by ''mask'' and then suspends the process until a signal is received.
174
1 perry 175
3 PerryLorier 176
1 perry 177 !!RETURN VALUE
5 JohnMcPherson 178 The functions __sigaction__ , __sigprocmask__ , __sigpending__ and __sigsuspend__ return 0 on success and -1 on error. (In the case of __sigsuspend__ there will be no success, and only the error return with __EINTR__ is possible.)
1 perry 179
3 PerryLorier 180
5 JohnMcPherson 181
182 !!ERRORS
183
184 ;[EINVAL]: An invalid signal was specified. This will also be generated if an attempt is made to change the action for [SIGKILL] or [SIGSTOP] , which cannot be caught.
185 ;[EFAULT]: ''act'' , ''oldact'' , ''set'' or ''oldset'' point to memory which is not a valid part of the process address space.
3 PerryLorier 186 ;[EINTR]: System call was interrupted.
5 JohnMcPherson 187
188
1 perry 189
190 !!NOTES
5 JohnMcPherson 191 It is not possible to block [SIGKILL] or [SIGSTOP] with the sigprocmask call. Attempts to do so will be silently ignored.
1 perry 192
5 JohnMcPherson 193 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 ''kill()'' or the ''raise()'' 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.
1 perry 194
5 JohnMcPherson 195 [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.
1 perry 196
5 JohnMcPherson 197 The POSIX spec only defines __SA_NOCLDSTOP__ . Use of other ''sa_flags'' is non-portable.
1 perry 198
3 PerryLorier 199 The __SA_RESETHAND__ flag is compatible with the SVr4 flag of the same name.
1 perry 200
5 JohnMcPherson 201 The __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 ''sa_mask'' settings).
1 perry 202
5 JohnMcPherson 203 The __SA_RESETHAND__ and __SA_NODEFER__ names for SVr4 compatibility are present only in library versions 3.0.9 and greater.
1 perry 204
5 JohnMcPherson 205 The __SA_SIGINFO__ flag is specified by POSIX.1b. Support for it was added in Linux 2.2.
1 perry 206
5 JohnMcPherson 207 __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.
1 perry 208
3 PerryLorier 209 See sigsetops(3) for details on manipulating signal sets.
1 perry 210
211 !!CONFORMING TO
5 JohnMcPherson 212 POSIX, SVr4. SVr4 does not document the [EINTR] condition.
213
214
1 perry 215
216 !!UNDOCUMENTED
5 JohnMcPherson 217 Before the introduction of __SA_SIGINFO__ it was also possible to get some additional information, namely by using a sa_handler with second argument of type ''struct sigcontext'' . See the relevant kernel sources for details. This use is obsolete now.
218
219
1 perry 220
221 !!SEE ALSO
5 JohnMcPherson 222 kill(1), kill(2), killpg(2), pause(2), raise(3), siginterrupt(3), signal(2), signal(7), sigsetops(3), sigvec(2)
This page is a man page (or other imported legacy content). We are unable to automatically determine the license status of this page.

PHP Warning

lib/blame.php:177: Warning: Invalid argument supplied for foreach() (...repeated 21 times)