1sigaction(2) System Calls sigaction(2)
2
3
4
6 sigaction - detailed signal management
7
9 #include <signal.h>
10
11 int sigaction(int sig, const struct sigaction *restrict act,
12 struct sigaction *restrict oact);
13
14
16 The sigaction() function allows the calling process to examine or spec‐
17 ify the action to be taken on delivery of a specific signal. See sig‐
18 nal.h(3HEAD) for an explanation of general signal concepts.
19
20
21 The sig argument specifies the signal and can be assigned any of the
22 signals specified in signal.h(3HEAD) except SIGKILL and SIGSTOP.
23
24
25 If the argument act is not NULL, it points to a structure specifying
26 the new action to be taken when delivering sig. If the argument oact is
27 not NULL, it points to a structure where the action previously associ‐
28 ated with sig is to be stored on return from sigaction().
29
30
31 The sigaction structure includes the following members:
32
33 void (*sa_handler)();
34 void (*sa_sigaction)(int, siginfo_t *, void *);
35 sigset_t sa_mask;
36 int sa_flags;
37
38
39
40 The storage occupied by sa_handler and sa_sigaction may overlap, and a
41 standard-conforming application (see standards(5)) must not use both
42 simultaneously.
43
44
45 The sa_handler member identifies the action to be associated with the
46 specified signal, if the SA_SIGINFO flag (see below) is cleared in the
47 sa_flags field of the sigaction structure. It may take any of the val‐
48 ues specified in signal.h(3HEAD) or that of a user specified signal
49 handler. If the SA_SIGINFO flag is set in the sa_flags field, the
50 sa_sigaction field specifies a signal-catching function.
51
52
53 The sa_mask member specifies a set of signals to be blocked while the
54 signal handler is active. On entry to the signal handler, that set of
55 signals is added to the set of signals already being blocked when the
56 signal is delivered. In addition, the signal that caused the handler to
57 be executed will also be blocked, unless the SA_NODEFER flag has been
58 specified. SIGSTOP and SIGKILL cannot be blocked (the system silently
59 enforces this restriction).
60
61
62 The sa_flags member specifies a set of flags used to modify the deliv‐
63 ery of the signal. It is formed by a logical OR of any of the following
64 values:
65
66 SA_ONSTACK If set and the signal is caught, and if the thread that
67 is chosen to processes a delivered signal has an alter‐
68 nate signal stack declared with sigaltstack(2), then it
69 will process the signal on that stack. Otherwise, the
70 signal is delivered on the thread's normal stack.
71
72
73 SA_RESETHAND If set and the signal is caught, the disposition of the
74 signal is reset to SIG_DFL and the signal will not be
75 blocked on entry to the signal handler (SIGILL, SIG‐
76 TRAP, and SIGPWR cannot be automatically reset when
77 delivered; the system silently enforces this restric‐
78 tion).
79
80
81 SA_NODEFER If set and the signal is caught, the signal will not be
82 automatically blocked by the kernel while it is being
83 caught.
84
85
86 SA_RESTART If set and the signal is caught, functions that are
87 interrupted by the execution of this signal's handler
88 are transparently restarted by the system, namely
89 fcntl(2), ioctl(2), wait(3C), waitid(2), and the fol‐
90 lowing functions on slow devices like terminals:
91 getmsg() and getpmsg() (see getmsg(2)); putmsg() and
92 putpmsg() (see putmsg(2)); pread(), read(), and readv()
93 (see read(2)); pwrite(), write(), and writev() (see
94 write(2)); recv(), recvfrom(), and recvmsg() (see
95 recv(3SOCKET)); and send(), sendto(), and sendmsg()
96 (see send(3SOCKET)). Otherwise, the function returns an
97 EINTR error.
98
99
100 SA_SIGINFO If cleared and the signal is caught, sig is passed as
101 the only argument to the signal-catching function. If
102 set and the signal is caught, two additional arguments
103 are passed to the signal-catching function. If the
104 second argument is not equal to NULL, it points to a
105 siginfo_t structure containing the reason why the sig‐
106 nal was generated (see siginfo.h(3HEAD)); the third
107 argument points to a ucontext_t structure containing
108 the receiving process's context when the signal was
109 delivered (see ucontext.h(3HEAD)).
110
111
112 SA_NOCLDWAIT If set and sig equals SIGCHLD, the system will not
113 create zombie processes when children of the calling
114 process exit. If the calling process subsequently
115 issues a wait(3C), it blocks until all of the calling
116 process's child processes terminate, and then returns
117 −1 with errno set to ECHILD.
118
119
120 SA_NOCLDSTOP If set and sig equals SIGCHLD, SIGCHLD will not be sent
121 to the calling process when its child processes stop or
122 continue.
123
124
126 Upon successful completion, 0 is returned. Otherwise, −1 is returned,
127 errno is set to indicate the error, and no new signal handler is
128 installed.
129
131 The sigaction() function will fail if:
132
133 EINVAL The value of the sig argument is not a valid signal number or
134 is equal to SIGKILL or SIGSTOP. In addition, if in a multi‐
135 threaded process, it is equal to SIGWAITING, SIGCANCEL, or
136 SIGLWP.
137
138
140 See attributes(5) for descriptions of the following attributes:
141
142
143
144
145 ┌─────────────────────────────┬─────────────────────────────┐
146 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
147 ├─────────────────────────────┼─────────────────────────────┤
148 │Interface Stability │Committed │
149 ├─────────────────────────────┼─────────────────────────────┤
150 │MT-Level │Async-Signal-Safe │
151 ├─────────────────────────────┼─────────────────────────────┤
152 │Standard │See standards(5). │
153 └─────────────────────────────┴─────────────────────────────┘
154
156 kill(1), Intro(2), exit(2), fcntl(2), getmsg(2), ioctl(2), kill(2),
157 pause(2), putmsg(2), read(2), sigaltstack(2), sigprocmask(2),
158 sigsend(2), sigsuspend(2), waitid(2), write(2), recv(3SOCKET),
159 send(3SOCKET), siginfo.h(3HEAD), signal(3C), signal.h(3HEAD), sigse‐
160 tops(3C), ucontext.h(3HEAD), wait(3C), attributes(5), standards(5)
161
163 The handler routine can be declared:
164
165 void handler (int sig, siginfo_t *sip, ucontext_t *ucp);
166
167
168
169 The sig argument is the signal number. The sip argument is a pointer
170 (to space on the stack) to a siginfo_t structure, which provides addi‐
171 tional detail about the delivery of the signal. The ucp argument is a
172 pointer (again to space on the stack) to a ucontext_t structure
173 (defined in <sys/ucontext.h>) which contains the context from before
174 the signal. It is not recommended that ucp be used by the handler to
175 restore the context from before the signal delivery.
176
177
178
179SunOS 5.11 23 Mar 2005 sigaction(2)