1 | .TH SIGACTION 2
|
---|
2 | .SH NAME
|
---|
3 | sigaction, signal \- manage signal state and handlers
|
---|
4 | .SH SYNOPSIS
|
---|
5 | .ft B
|
---|
6 | #include <signal.h>
|
---|
7 |
|
---|
8 | .in +5
|
---|
9 | .ti -5
|
---|
10 | int sigaction(int \fIsig\fP, const struct sigaction *\fIact\fP, struct sigaction *\fIoact\fP)
|
---|
11 | .in -5
|
---|
12 | .br
|
---|
13 | void (*signal(int \fIsig\fP, void (*\fIhandler\fP)(int)))(int);
|
---|
14 | .ft P
|
---|
15 | .SH DESCRIPTION
|
---|
16 | .de SP
|
---|
17 | .if t .sp 0.4
|
---|
18 | .if n .sp
|
---|
19 | ..
|
---|
20 | .B Sigaction()
|
---|
21 | is used to examine, set, or modify the attributes of a signal. The argument
|
---|
22 | .I sig
|
---|
23 | is the signal in question. The
|
---|
24 | .I act
|
---|
25 | argument points to a structure containing the new attributes of the signal,
|
---|
26 | the structure pointed to by
|
---|
27 | .I oact
|
---|
28 | will receive the old attributes that were in effect before the call.
|
---|
29 | .PP
|
---|
30 | The
|
---|
31 | .I act
|
---|
32 | and
|
---|
33 | .I oact
|
---|
34 | arguments may be
|
---|
35 | .B NULL
|
---|
36 | to indicate that either no new attributes are to be set, or that the old
|
---|
37 | attributes are not of interest.
|
---|
38 | .PP
|
---|
39 | The structure containing the signal attributes is defined in <signal.h> and
|
---|
40 | looks like this:
|
---|
41 | .PP
|
---|
42 | .RS
|
---|
43 | .nf
|
---|
44 | .ft B
|
---|
45 | .ta +4n +12n
|
---|
46 | struct sigaction {
|
---|
47 | void (*sa_handler)(int sig);
|
---|
48 | sigset_t sa_mask;
|
---|
49 | int sa_flags;
|
---|
50 | };
|
---|
51 | .ft R
|
---|
52 | .fi
|
---|
53 | .RE
|
---|
54 | .PP
|
---|
55 | The
|
---|
56 | .B sa_handler
|
---|
57 | field contains the address of a signal handler, a function that is called
|
---|
58 | when the process is signalled, or one of these special constants:
|
---|
59 | .PP
|
---|
60 | .TP 12
|
---|
61 | .B SIG_DFL
|
---|
62 | Default signal handling is to be performed. This usually means that the
|
---|
63 | process is killed, but some signals may be ignored by default.
|
---|
64 | .TP
|
---|
65 | .B SIG_IGN
|
---|
66 | Ignore the signal.
|
---|
67 | .PP
|
---|
68 | The
|
---|
69 | .B sa_mask
|
---|
70 | field indicates a set of signals that must be blocked when the signal is
|
---|
71 | being handled. Whether the signal
|
---|
72 | .I sig
|
---|
73 | itself is blocked when being handled is not controlled by this mask. The
|
---|
74 | mask is of a "signal set" type that is to be manipulated by the
|
---|
75 | .BR sigset (3)
|
---|
76 | functions.
|
---|
77 | .PP
|
---|
78 | How the signal is handled precisely is specified by bits in
|
---|
79 | .BR sa_flags .
|
---|
80 | If none of the flags is set then the handler is called when the signal
|
---|
81 | arrives. The signal is blocked during the call to the handler, and
|
---|
82 | unblocked when the handler returns. A system call that is interrupted
|
---|
83 | returns
|
---|
84 | .B \-1
|
---|
85 | with
|
---|
86 | .B errno
|
---|
87 | set to
|
---|
88 | .BR EINTR .
|
---|
89 | The following bit flags can be set to modify this behaviour:
|
---|
90 | .PP
|
---|
91 | .TP 15
|
---|
92 | .B SA_RESETHAND
|
---|
93 | Reset the signal handler to
|
---|
94 | .B SIG_DFL
|
---|
95 | when the signal is caught.
|
---|
96 | .TP
|
---|
97 | .B SA_NODEFER
|
---|
98 | Do not block the signal on entry to the handler.
|
---|
99 | .TP
|
---|
100 | .B SA_COMPAT
|
---|
101 | Handle the signal in a way that is compatible with the the old
|
---|
102 | .B signal()
|
---|
103 | call.
|
---|
104 | .PP
|
---|
105 | The old
|
---|
106 | .B signal()
|
---|
107 | signal system call sets a signal handler for a given signal and returns the
|
---|
108 | old signal handler. No signals are blocked, the flags are
|
---|
109 | .BR "SA_RESETHAND | SA_NODEFER | SA_COMPAT" .
|
---|
110 | New code should not use
|
---|
111 | .BR signal() .
|
---|
112 | Note that
|
---|
113 | .B signal()
|
---|
114 | and all of the
|
---|
115 | .B SA_*
|
---|
116 | flags are MINIX 3 extensions.
|
---|
117 | .PP
|
---|
118 | Signal handlers are reset to
|
---|
119 | .B SIG_DFL
|
---|
120 | on an
|
---|
121 | .BR execve (2).
|
---|
122 | Signals that are ignored stay ignored.
|
---|
123 | .SS Signals
|
---|
124 | MINIX 3 knows about the following signals:
|
---|
125 | .PP
|
---|
126 | .nf
|
---|
127 | .ta +11n +7n +8n
|
---|
128 | signal num notes description
|
---|
129 | .SP
|
---|
130 | SIGHUP 1 k Hangup
|
---|
131 | SIGINT 2 k Interrupt (usually DEL or CTRL\-C)
|
---|
132 | SIGQUIT 3 kc Quit (usually CTRL\-\e)
|
---|
133 | SIGILL 4 kc Illegal instruction
|
---|
134 | SIGTRAP 5 xkc Trace trap
|
---|
135 | SIGABRT 6 kc Abort program
|
---|
136 | SIGFPE 8 k Floating point exception
|
---|
137 | SIGKILL 9 k Kill
|
---|
138 | SIGUSR1 10 k User defined signal #1
|
---|
139 | SIGSEGV 11 kc Segmentation fault
|
---|
140 | SIGUSR2 12 k User defined signal #2
|
---|
141 | SIGPIPE 13 k Write to a pipe with no reader
|
---|
142 | SIGALRM 14 k Alarm clock
|
---|
143 | SIGTERM 15 k Terminate (default for kill(1))
|
---|
144 | SIGCHLD 17 pvi Child process terminated
|
---|
145 | SIGCONT 18 p Continue if stopped
|
---|
146 | SIGSTOP 19 ps Stop signal
|
---|
147 | SIGTSTP 20 ps Interactive stop signal
|
---|
148 | SIGTTIN 21 ps Background read
|
---|
149 | SIGTTOU 22 ps Background write
|
---|
150 | SIGWINCH 23 xvi Window size change
|
---|
151 | .ft R
|
---|
152 | .fi
|
---|
153 | .PP
|
---|
154 | The letters in the notes column indicate:
|
---|
155 | .PP
|
---|
156 | .TP 5
|
---|
157 | .B k
|
---|
158 | The process is killed if the signal is not caught.
|
---|
159 | .TP
|
---|
160 | .B c
|
---|
161 | The signal causes a core dump.
|
---|
162 | .TP
|
---|
163 | .B i
|
---|
164 | The signal is ignored if not caught.
|
---|
165 | .TP
|
---|
166 | .B v
|
---|
167 | Only Minix-vmd implements this signal.
|
---|
168 | .TP
|
---|
169 | .B x
|
---|
170 | MINIX 3 extension, not defined by \s-2POSIX\s+2.
|
---|
171 | .TP
|
---|
172 | .B p
|
---|
173 | These signals are not implemented, but \s-2POSIX\s+2 requires that they are
|
---|
174 | defined.
|
---|
175 | .TP
|
---|
176 | .B s
|
---|
177 | The process should be stopped, but is killed instead.
|
---|
178 | .PP
|
---|
179 | The
|
---|
180 | .B SIGKILL
|
---|
181 | signal cannot be caught or ignored. The
|
---|
182 | .B SIGILL
|
---|
183 | and
|
---|
184 | .B SIGTRAP
|
---|
185 | signals cannot be automatically reset. The system silently enforces these
|
---|
186 | restrictions. This may or may not be reflected by the attributes of these
|
---|
187 | signals and the signal masks.
|
---|
188 | .SS Types
|
---|
189 | \s-2POSIX\s+2 prescribes that <sys/types.h> has the following definition:
|
---|
190 | .PP
|
---|
191 | .RS
|
---|
192 | .B "typedef int (*sighandler_t)(int)"
|
---|
193 | .RE
|
---|
194 | .PP
|
---|
195 | With this type the following declarations can be made:
|
---|
196 | .PP
|
---|
197 | .RS
|
---|
198 | .ft B
|
---|
199 | .nf
|
---|
200 | sighandler_t sa_handler;
|
---|
201 | sighandler_t signal(int \fIsig\fP, sighandler_t \fIhandler\fP);
|
---|
202 | .fi
|
---|
203 | .ft R
|
---|
204 | .RE
|
---|
205 | .PP
|
---|
206 | This may help you to understand the earlier declarations better. The
|
---|
207 | .B sighandler_t
|
---|
208 | type is also very useful in old style C code that is compiled by a compiler
|
---|
209 | for standard C.
|
---|
210 | .SH "SEE ALSO"
|
---|
211 | .BR kill (1),
|
---|
212 | .BR kill (2),
|
---|
213 | .BR pause (2),
|
---|
214 | .BR sigprocmask (2),
|
---|
215 | .BR sigsuspend (2),
|
---|
216 | .BR sigpending (2),
|
---|
217 | .BR sigset (3).
|
---|
218 | .SH DIAGNOSTICS
|
---|
219 | .B Sigaction()
|
---|
220 | returns
|
---|
221 | .B 0
|
---|
222 | on success or
|
---|
223 | .B \-1
|
---|
224 | on error.
|
---|
225 | .B Signal()
|
---|
226 | returns the old handler on success or
|
---|
227 | .B SIG_ERR
|
---|
228 | on error. The error code may be:
|
---|
229 | .PP
|
---|
230 | .TP 10
|
---|
231 | .B EINVAL
|
---|
232 | Bad signal number.
|
---|
233 | .TP
|
---|
234 | .B EFAULT
|
---|
235 | Bad
|
---|
236 | .I act
|
---|
237 | or
|
---|
238 | .I oact
|
---|
239 | addresses.
|
---|
240 | .SH AUTHOR
|
---|
241 | Kees J. Bot (kjb@cs.vu.nl)
|
---|
242 |
|
---|
243 | .\"
|
---|
244 | .\" $PchId: sigaction.2,v 1.2 1996/04/11 06:00:28 philip Exp $
|
---|