1.\" Copyright (c) 1980, 1990, 1993 2.\" The Regents of the University of California. All rights reserved. 3.\" 4.\" Redistribution and use in source and binary forms, with or without 5.\" modification, are permitted provided that the following conditions 6.\" are met: 7.\" 1. Redistributions of source code must retain the above copyright 8.\" notice, this list of conditions and the following disclaimer. 9.\" 2. Redistributions in binary form must reproduce the above copyright 10.\" notice, this list of conditions and the following disclaimer in the 11.\" documentation and/or other materials provided with the distribution. 12.\" 3. All advertising materials mentioning features or use of this software 13.\" must display the following acknowledgement: 14.\" This product includes software developed by the University of 15.\" California, Berkeley and its contributors. 16.\" 4. Neither the name of the University nor the names of its contributors 17.\" may be used to endorse or promote products derived from this software 18.\" without specific prior written permission. 19.\" 20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30.\" SUCH DAMAGE. 31.\" 32.\" From: @(#)sigaction.2 8.2 (Berkeley) 4/3/94
| 1.\" Copyright (c) 1980, 1990, 1993 2.\" The Regents of the University of California. All rights reserved. 3.\" 4.\" Redistribution and use in source and binary forms, with or without 5.\" modification, are permitted provided that the following conditions 6.\" are met: 7.\" 1. Redistributions of source code must retain the above copyright 8.\" notice, this list of conditions and the following disclaimer. 9.\" 2. Redistributions in binary form must reproduce the above copyright 10.\" notice, this list of conditions and the following disclaimer in the 11.\" documentation and/or other materials provided with the distribution. 12.\" 3. All advertising materials mentioning features or use of this software 13.\" must display the following acknowledgement: 14.\" This product includes software developed by the University of 15.\" California, Berkeley and its contributors. 16.\" 4. Neither the name of the University nor the names of its contributors 17.\" may be used to endorse or promote products derived from this software 18.\" without specific prior written permission. 19.\" 20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30.\" SUCH DAMAGE. 31.\" 32.\" From: @(#)sigaction.2 8.2 (Berkeley) 4/3/94
|
34.\" 35.Dd April 3, 1994 36.Dt SIGACTION 2 37.Os 38.Sh NAME 39.Nm sigaction 40.Nd software signal facilities 41.Sh SYNOPSIS 42.Fd #include <signal.h> 43.Bd -literal 44struct sigaction { 45 /* 46 * Signal handler function if flag SA_SIGINFO is not used and for 47 * SIG_DFL and SIG_IGN. 48 */ 49 void (*sa_handler)(int); 50 51 /* Signal handler function if flag SA_SIGINFO is used */ 52 void (*sa_sigaction)(int, siginfo_t *, void *); 53 54 sigset_t sa_mask; /* signal mask to apply */ 55 int sa_flags; /* see signal options below */ 56}; 57.Ed 58.Ft int 59.Fn sigaction "int sig" "const struct sigaction *act" "struct sigaction *oact" 60.Sh DESCRIPTION 61The system defines a set of signals that may be delivered to a process. 62Signal delivery resembles the occurrence of a hardware interrupt: 63the signal is normally blocked from further occurrence, the current process 64context is saved, and a new one is built. A process may specify a 65.Em handler 66to which a signal is delivered, or specify that a signal is to be 67.Em ignored . 68A process may also specify that a default action is to be taken 69by the system when a signal occurs. 70A signal may also be 71.Em blocked , 72in which case its delivery is postponed until it is 73.Em unblocked . 74The action to be taken on delivery is determined at the time 75of delivery. 76Normally, signal handlers execute on the current stack 77of the process. This may be changed, on a per-handler basis, 78so that signals are taken on a special 79.Em "signal stack" . 80.Pp 81Signal routines normally execute with the signal that caused their 82invocation 83.Em blocked , 84but other signals may yet occur. 85A global 86.Em "signal mask" 87defines the set of signals currently blocked from delivery 88to a process. The signal mask for a process is initialized 89from that of its parent (normally empty). It 90may be changed with a 91.Xr sigprocmask 2 92call, or when a signal is delivered to the process. 93.Pp 94When a signal 95condition arises for a process, the signal is added to a set of 96signals pending for the process. 97If the signal is not currently 98.Em blocked 99by the process then it is delivered to the process. 100Signals may be delivered any time a process enters the operating system 101(e.g., during a system call, page fault or trap, or clock interrupt). 102If multiple signals are ready to be delivered at the same time, 103any signals that could be caused by traps are delivered first. 104Additional signals may be processed at the same time, with each 105appearing to interrupt the handlers for the previous signals 106before their first instructions. 107The set of pending signals is returned by the 108.Xr sigpending 2 109function. 110When a caught signal 111is delivered, the current state of the process is saved, 112a new signal mask is calculated (as described below), 113and the signal handler is invoked. The call to the handler 114is arranged so that if the signal handling routine returns 115normally the process will resume execution in the context 116from before the signal's delivery. 117If the process wishes to resume in a different context, then it 118must arrange to restore the previous context itself. 119.Pp 120When a signal is delivered to a process a new signal mask is 121installed for the duration of the process' signal handler 122(or until a 123.Xr sigprocmask 124call is made). 125This mask is formed by taking the union of the current signal mask set, 126the signal to be delivered, and 127the signal mask associated with the handler to be invoked. 128.Pp 129.Fn Sigaction 130assigns an action for a signal specified by 131.Fa sig . 132If 133.Fa act 134is non-zero, it 135specifies an action 136.Pf ( Dv SIG_DFL , 137.Dv SIG_IGN , 138or a handler routine) and mask 139to be used when delivering the specified signal. 140If 141.Fa oact 142is non-zero, the previous handling information for the signal 143is returned to the user. 144.Pp 145Once a signal handler is installed, it normally remains installed 146until another 147.Fn sigaction 148call is made, or an 149.Xr execve 2 150is performed. 151A signal-specific default action may be reset by 152setting 153.Fa sa_handler 154to 155.Dv SIG_DFL . 156The defaults are process termination, possibly with core dump; 157no action; stopping the process; or continuing the process. 158See the signal list below for each signal's default action. 159If 160.Fa sa_handler 161is 162.Dv SIG_DFL , 163the default action for the signal is to discard the signal, 164and if a signal is pending, 165the pending signal is discarded even if the signal is masked. 166If 167.Fa sa_handler 168is set to 169.Dv SIG_IGN 170current and pending instances 171of the signal are ignored and discarded. 172.Pp 173Options may be specified by setting 174.Em sa_flags . 175The meaning of the various bits is as follows: 176.Bl -tag -offset indent -width SA_RESETHANDXX 177.It Dv SA_NOCLDSTOP 178If this bit is set when installing a catching function 179for the 180.Dv SIGCHLD 181signal, 182the 183.Dv SIGCHLD 184signal will be generated only when a child process exits, 185not when a child process stops. 186.It Dv SA_NOCLDWAIT 187If this bit is set when calling 188.Fn sigaction 189for the 190.Dv SIGCHLD 191signal, the system will not create zombie processes when children of 192the calling process exit. If the calling process subsequently issues 193a 194.Xr wait 2 195(or equivalent), it blocks until all of the calling process's child 196processes terminate, and then returns a value of -1 with errno set to 197.Dv ECHILD . 198.It Dv SA_ONSTACK 199If this bit is set, the system will deliver the signal to the process 200on a 201.Em "signal stack" , 202specified with 203.Xr sigaltstack 2 . 204.It Dv SA_NODEFER 205If this bit is set, further occurrences of the delivered signal are 206not masked during the execution of the handler. 207.It Dv SA_RESETHAND 208If this bit is set, the handler is reset back to 209.Dv SIG_DFL 210at the moment the signal is delivered. 211.It Dv SA_SIGINFO 212If this bit is set, the handler function is assumed to be pointed to 213by the sa_sigaction member of struct sigaction and should match the 214prototype shown above or as below in 215.Sx EXAMPLES . 216This bit should not be set when assigning 217.Dv SIG_DFL 218or 219.Dv SIG_IGN . 220.El 221.Pp 222If a signal is caught during the system calls listed below, 223the call may be forced to terminate 224with the error 225.Dv EINTR , 226the call may return with a data transfer shorter than requested, 227or the call may be restarted. 228Restart of pending calls is requested 229by setting the 230.Dv SA_RESTART 231bit in 232.Ar sa_flags . 233The affected system calls include 234.Xr open 2 , 235.Xr read 2 , 236.Xr write 2 , 237.Xr sendto 2 , 238.Xr recvfrom 2 , 239.Xr sendmsg 2 240and 241.Xr recvmsg 2 242on a communications channel or a slow device (such as a terminal, 243but not a regular file) 244and during a 245.Xr wait 2 246or 247.Xr ioctl 2 . 248However, calls that have already committed are not restarted, 249but instead return a partial success (for example, a short read count). 250.Pp 251After a 252.Xr fork 2 253or 254.Xr vfork 2 255all signals, the signal mask, the signal stack, 256and the restart/interrupt flags are inherited by the child. 257.Pp 258.Xr Execve 2 259reinstates the default 260action for all signals which were caught and 261resets all signals to be caught on the user stack. 262Ignored signals remain ignored; 263the signal mask remains the same; 264signals that restart pending system calls continue to do so. 265.Pp 266The following is a list of all signals 267with names as in the include file 268.Aq Pa signal.h : 269.Bl -column SIGVTALARMXX "create core imagexxx" 270.It Sy " NAME " " Default Action " " Description" 271.It Dv SIGHUP No " terminate process" " terminal line hangup" 272.It Dv SIGINT No " terminate process" " interrupt program" 273.It Dv SIGQUIT No " create core image" " quit program" 274.It Dv SIGILL No " create core image" " illegal instruction" 275.It Dv SIGTRAP No " create core image" " trace trap" 276.It Dv SIGABRT No " create core image" Xr abort 3 277call (formerly 278.Dv SIGIOT ) 279.It Dv SIGEMT No " create core image" " emulate instruction executed" 280.It Dv SIGFPE No " create core image" " floating-point exception" 281.It Dv SIGKILL No " terminate process" " kill program" 282.It Dv SIGBUS No " create core image" " bus error" 283.It Dv SIGSEGV No " create core image" " segmentation violation" 284.It Dv SIGSYS No " create core image" " non-existent system call invoked" 285.It Dv SIGPIPE No " terminate process" " write on a pipe with no reader" 286.It Dv SIGALRM No " terminate process" " real-time timer expired" 287.It Dv SIGTERM No " terminate process" " software termination signal" 288.It Dv SIGURG No " discard signal" " urgent condition present on socket" 289.It Dv SIGSTOP No " stop process" " stop (cannot be caught or ignored)" 290.It Dv SIGTSTP No " stop process" " stop signal generated from keyboard" 291.It Dv SIGCONT No " discard signal" " continue after stop" 292.It Dv SIGCHLD No " discard signal" " child status has changed" 293.It Dv SIGTTIN No " stop process" " background read attempted from control terminal" 294.It Dv SIGTTOU No " stop process" " background write attempted to control terminal" 295.It Dv SIGIO No " discard signal" Tn " I/O" 296is possible on a descriptor (see 297.Xr fcntl 2 ) 298.It Dv SIGXCPU No " terminate process" " cpu time limit exceeded (see" 299.Xr setrlimit 2 ) 300.It Dv SIGXFSZ No " terminate process" " file size limit exceeded (see" 301.Xr setrlimit 2 ) 302.It Dv SIGVTALRM No " terminate process" " virtual time alarm (see" 303.Xr setitimer 2 ) 304.It Dv SIGPROF No " terminate process" " profiling timer alarm (see" 305.Xr setitimer 2 ) 306.It Dv SIGWINCH No " discard signal" " Window size change" 307.It Dv SIGINFO No " discard signal" " status request from keyboard" 308.It Dv SIGUSR1 No " terminate process" " User defined signal 1" 309.It Dv SIGUSR2 No " terminate process" " User defined signal 2" 310.El 311.Sh NOTE 312The 313.Fa sa_mask 314field specified in 315.Fa act 316is not allowed to block 317.Dv SIGKILL 318or 319.Dv SIGSTOP . 320Any attempt to do so will be silently ignored. 321.Pp 322The following functions are either reentrant or not interruptible
| 34.\" 35.Dd April 3, 1994 36.Dt SIGACTION 2 37.Os 38.Sh NAME 39.Nm sigaction 40.Nd software signal facilities 41.Sh SYNOPSIS 42.Fd #include <signal.h> 43.Bd -literal 44struct sigaction { 45 /* 46 * Signal handler function if flag SA_SIGINFO is not used and for 47 * SIG_DFL and SIG_IGN. 48 */ 49 void (*sa_handler)(int); 50 51 /* Signal handler function if flag SA_SIGINFO is used */ 52 void (*sa_sigaction)(int, siginfo_t *, void *); 53 54 sigset_t sa_mask; /* signal mask to apply */ 55 int sa_flags; /* see signal options below */ 56}; 57.Ed 58.Ft int 59.Fn sigaction "int sig" "const struct sigaction *act" "struct sigaction *oact" 60.Sh DESCRIPTION 61The system defines a set of signals that may be delivered to a process. 62Signal delivery resembles the occurrence of a hardware interrupt: 63the signal is normally blocked from further occurrence, the current process 64context is saved, and a new one is built. A process may specify a 65.Em handler 66to which a signal is delivered, or specify that a signal is to be 67.Em ignored . 68A process may also specify that a default action is to be taken 69by the system when a signal occurs. 70A signal may also be 71.Em blocked , 72in which case its delivery is postponed until it is 73.Em unblocked . 74The action to be taken on delivery is determined at the time 75of delivery. 76Normally, signal handlers execute on the current stack 77of the process. This may be changed, on a per-handler basis, 78so that signals are taken on a special 79.Em "signal stack" . 80.Pp 81Signal routines normally execute with the signal that caused their 82invocation 83.Em blocked , 84but other signals may yet occur. 85A global 86.Em "signal mask" 87defines the set of signals currently blocked from delivery 88to a process. The signal mask for a process is initialized 89from that of its parent (normally empty). It 90may be changed with a 91.Xr sigprocmask 2 92call, or when a signal is delivered to the process. 93.Pp 94When a signal 95condition arises for a process, the signal is added to a set of 96signals pending for the process. 97If the signal is not currently 98.Em blocked 99by the process then it is delivered to the process. 100Signals may be delivered any time a process enters the operating system 101(e.g., during a system call, page fault or trap, or clock interrupt). 102If multiple signals are ready to be delivered at the same time, 103any signals that could be caused by traps are delivered first. 104Additional signals may be processed at the same time, with each 105appearing to interrupt the handlers for the previous signals 106before their first instructions. 107The set of pending signals is returned by the 108.Xr sigpending 2 109function. 110When a caught signal 111is delivered, the current state of the process is saved, 112a new signal mask is calculated (as described below), 113and the signal handler is invoked. The call to the handler 114is arranged so that if the signal handling routine returns 115normally the process will resume execution in the context 116from before the signal's delivery. 117If the process wishes to resume in a different context, then it 118must arrange to restore the previous context itself. 119.Pp 120When a signal is delivered to a process a new signal mask is 121installed for the duration of the process' signal handler 122(or until a 123.Xr sigprocmask 124call is made). 125This mask is formed by taking the union of the current signal mask set, 126the signal to be delivered, and 127the signal mask associated with the handler to be invoked. 128.Pp 129.Fn Sigaction 130assigns an action for a signal specified by 131.Fa sig . 132If 133.Fa act 134is non-zero, it 135specifies an action 136.Pf ( Dv SIG_DFL , 137.Dv SIG_IGN , 138or a handler routine) and mask 139to be used when delivering the specified signal. 140If 141.Fa oact 142is non-zero, the previous handling information for the signal 143is returned to the user. 144.Pp 145Once a signal handler is installed, it normally remains installed 146until another 147.Fn sigaction 148call is made, or an 149.Xr execve 2 150is performed. 151A signal-specific default action may be reset by 152setting 153.Fa sa_handler 154to 155.Dv SIG_DFL . 156The defaults are process termination, possibly with core dump; 157no action; stopping the process; or continuing the process. 158See the signal list below for each signal's default action. 159If 160.Fa sa_handler 161is 162.Dv SIG_DFL , 163the default action for the signal is to discard the signal, 164and if a signal is pending, 165the pending signal is discarded even if the signal is masked. 166If 167.Fa sa_handler 168is set to 169.Dv SIG_IGN 170current and pending instances 171of the signal are ignored and discarded. 172.Pp 173Options may be specified by setting 174.Em sa_flags . 175The meaning of the various bits is as follows: 176.Bl -tag -offset indent -width SA_RESETHANDXX 177.It Dv SA_NOCLDSTOP 178If this bit is set when installing a catching function 179for the 180.Dv SIGCHLD 181signal, 182the 183.Dv SIGCHLD 184signal will be generated only when a child process exits, 185not when a child process stops. 186.It Dv SA_NOCLDWAIT 187If this bit is set when calling 188.Fn sigaction 189for the 190.Dv SIGCHLD 191signal, the system will not create zombie processes when children of 192the calling process exit. If the calling process subsequently issues 193a 194.Xr wait 2 195(or equivalent), it blocks until all of the calling process's child 196processes terminate, and then returns a value of -1 with errno set to 197.Dv ECHILD . 198.It Dv SA_ONSTACK 199If this bit is set, the system will deliver the signal to the process 200on a 201.Em "signal stack" , 202specified with 203.Xr sigaltstack 2 . 204.It Dv SA_NODEFER 205If this bit is set, further occurrences of the delivered signal are 206not masked during the execution of the handler. 207.It Dv SA_RESETHAND 208If this bit is set, the handler is reset back to 209.Dv SIG_DFL 210at the moment the signal is delivered. 211.It Dv SA_SIGINFO 212If this bit is set, the handler function is assumed to be pointed to 213by the sa_sigaction member of struct sigaction and should match the 214prototype shown above or as below in 215.Sx EXAMPLES . 216This bit should not be set when assigning 217.Dv SIG_DFL 218or 219.Dv SIG_IGN . 220.El 221.Pp 222If a signal is caught during the system calls listed below, 223the call may be forced to terminate 224with the error 225.Dv EINTR , 226the call may return with a data transfer shorter than requested, 227or the call may be restarted. 228Restart of pending calls is requested 229by setting the 230.Dv SA_RESTART 231bit in 232.Ar sa_flags . 233The affected system calls include 234.Xr open 2 , 235.Xr read 2 , 236.Xr write 2 , 237.Xr sendto 2 , 238.Xr recvfrom 2 , 239.Xr sendmsg 2 240and 241.Xr recvmsg 2 242on a communications channel or a slow device (such as a terminal, 243but not a regular file) 244and during a 245.Xr wait 2 246or 247.Xr ioctl 2 . 248However, calls that have already committed are not restarted, 249but instead return a partial success (for example, a short read count). 250.Pp 251After a 252.Xr fork 2 253or 254.Xr vfork 2 255all signals, the signal mask, the signal stack, 256and the restart/interrupt flags are inherited by the child. 257.Pp 258.Xr Execve 2 259reinstates the default 260action for all signals which were caught and 261resets all signals to be caught on the user stack. 262Ignored signals remain ignored; 263the signal mask remains the same; 264signals that restart pending system calls continue to do so. 265.Pp 266The following is a list of all signals 267with names as in the include file 268.Aq Pa signal.h : 269.Bl -column SIGVTALARMXX "create core imagexxx" 270.It Sy " NAME " " Default Action " " Description" 271.It Dv SIGHUP No " terminate process" " terminal line hangup" 272.It Dv SIGINT No " terminate process" " interrupt program" 273.It Dv SIGQUIT No " create core image" " quit program" 274.It Dv SIGILL No " create core image" " illegal instruction" 275.It Dv SIGTRAP No " create core image" " trace trap" 276.It Dv SIGABRT No " create core image" Xr abort 3 277call (formerly 278.Dv SIGIOT ) 279.It Dv SIGEMT No " create core image" " emulate instruction executed" 280.It Dv SIGFPE No " create core image" " floating-point exception" 281.It Dv SIGKILL No " terminate process" " kill program" 282.It Dv SIGBUS No " create core image" " bus error" 283.It Dv SIGSEGV No " create core image" " segmentation violation" 284.It Dv SIGSYS No " create core image" " non-existent system call invoked" 285.It Dv SIGPIPE No " terminate process" " write on a pipe with no reader" 286.It Dv SIGALRM No " terminate process" " real-time timer expired" 287.It Dv SIGTERM No " terminate process" " software termination signal" 288.It Dv SIGURG No " discard signal" " urgent condition present on socket" 289.It Dv SIGSTOP No " stop process" " stop (cannot be caught or ignored)" 290.It Dv SIGTSTP No " stop process" " stop signal generated from keyboard" 291.It Dv SIGCONT No " discard signal" " continue after stop" 292.It Dv SIGCHLD No " discard signal" " child status has changed" 293.It Dv SIGTTIN No " stop process" " background read attempted from control terminal" 294.It Dv SIGTTOU No " stop process" " background write attempted to control terminal" 295.It Dv SIGIO No " discard signal" Tn " I/O" 296is possible on a descriptor (see 297.Xr fcntl 2 ) 298.It Dv SIGXCPU No " terminate process" " cpu time limit exceeded (see" 299.Xr setrlimit 2 ) 300.It Dv SIGXFSZ No " terminate process" " file size limit exceeded (see" 301.Xr setrlimit 2 ) 302.It Dv SIGVTALRM No " terminate process" " virtual time alarm (see" 303.Xr setitimer 2 ) 304.It Dv SIGPROF No " terminate process" " profiling timer alarm (see" 305.Xr setitimer 2 ) 306.It Dv SIGWINCH No " discard signal" " Window size change" 307.It Dv SIGINFO No " discard signal" " status request from keyboard" 308.It Dv SIGUSR1 No " terminate process" " User defined signal 1" 309.It Dv SIGUSR2 No " terminate process" " User defined signal 2" 310.El 311.Sh NOTE 312The 313.Fa sa_mask 314field specified in 315.Fa act 316is not allowed to block 317.Dv SIGKILL 318or 319.Dv SIGSTOP . 320Any attempt to do so will be silently ignored. 321.Pp 322The following functions are either reentrant or not interruptible
|
324invoke them, without restriction, from signal-catching functions: 325.Pp 326Base Interfaces: 327.Pp 328.Fn _exit , 329.Fn access , 330.Fn alarm , 331.Fn cfgetispeed , 332.Fn cfgetospeed , 333.Fn cfsetispeed , 334.Fn cfsetospeed , 335.Fn chdir , 336.Fn chmod , 337.Fn chown , 338.Fn close , 339.Fn creat , 340.Fn dup , 341.Fn dup2 , 342.Fn execle , 343.Fn execve , 344.Fn fcntl , 345.Fn fork , 346.Fn fpathconf , 347.Fn fstat , 348.Fn fsync , 349.Fn getegid , 350.Fn geteuid , 351.Fn getgid , 352.Fn getgroups , 353.Fn getpgrp , 354.Fn getpid , 355.Fn getppid , 356.Fn getuid , 357.Fn kill , 358.Fn link , 359.Fn lseek , 360.Fn mkdir , 361.Fn mkfifo , 362.Fn open , 363.Fn pathconf , 364.Fn pause , 365.Fn pipe , 366.Fn raise , 367.Fn read , 368.Fn rename , 369.Fn rmdir , 370.Fn setgid , 371.Fn setpgid , 372.Fn setsid , 373.Fn setuid , 374.Fn sigaction , 375.Fn sigaddset , 376.Fn sigdelset , 377.Fn sigemptyset , 378.Fn sigfillset , 379.Fn sigismember , 380.Fn signal , 381.Fn sigpending , 382.Fn sigprocmask , 383.Fn sigsuspend , 384.Fn sleep , 385.Fn stat , 386.Fn sysconf , 387.Fn tcdrain , 388.Fn tcflow , 389.Fn tcflush , 390.Fn tcgetattr , 391.Fn tcgetpgrp , 392.Fn tcsendbreak , 393.Fn tcsetattr , 394.Fn tcsetpgrp , 395.Fn time , 396.Fn times , 397.Fn umask , 398.Fn uname , 399.Fn unlink , 400.Fn utime , 401.Fn wait , 402.Fn waitpid , 403.Fn write . 404.Pp 405Realtime Interfaces: 406.Pp 407.Fn aio_error , 408.Fn clock_gettime , 409.Fn sigpause , 410.Fn timer_getoverrun , 411.Fn aio_return , 412.Fn fdatasync , 413.Fn sigqueue , 414.Fn timer_gettime , 415.Fn aio_suspend , 416.Fn sem_post , 417.Fn sigset , 418.Fn timer_settime . 419.Pp 420All functions not in the above lists are considered to be unsafe 421with respect to signals. That is to say, the behaviour of such 422functions when called from a signal handler is undefined. 423.Sh RETURN VALUES 424A 0 value indicated that the call succeeded. A \-1 return value 425indicates an error occurred and 426.Va errno 427is set to indicated the reason. 428.Sh EXAMPLES 429There are three possible prototypes the handler may match: 430.Bl -tag -offset indent -width short 431.It ANSI C: 432.Fd 433void handler(int); 434.It Traditional BSD style: 435.Fd 436void handler(int, int code, struct sigcontext *scp); 437.It POSIX SA_SIGINFO: 438.Fd 439void handler(int, siginfo_t *info, void *context); 440.El 441.Pp 442The handler function should match the SA_SIGINFO prototype if the 443SA_SIGINFO bit is set in flags. 444It then should be pointed to by the 445.Dv sa_siginfo 446member of 447.Dv struct sigaction . 448Note that you should not assign SIG_DFL or SIG_IGN this way. 449.Pp 450If the SA_SIGINFO flag is not set, the handler function should match 451either the ANSI C or traditional BSD prototype and be pointed to by 452the 453.Dv sa_handler 454member of 455.Dv struct sigaction . 456In pratice, 457.Fx 458always sends the three arguments of the latter and since the ANSI C 459prototype is a subset, both will work. 460The 461.Dv sa_handler 462member declaration in 463.Fx 464include files is that of ANSI C (as required by POSIX), 465so a function pointer of a BSD-style function needs to be casted to 466compile without warning. 467The traditional BSD style is not portable and since its capabilities 468are a full subset of a SA_SIGINFO handler, 469its use is deprecated. 470.Pp 471The 472.Fa sig 473argument is the signal number, one of the 474.Dv SIG... 475values from <signal.h>. 476.Pp 477The 478.Fa code 479argument of the BSD-style handler and the 480.Dv si_code 481member of the 482.Dv info 483argument to a SA_SIGINFO handler contain a numeric code explaning the 484cause of the signal, usually one of the 485.Dv SI_... 486values from 487<sys/signal.h> or codes specific to a signal, i.e. one of the 488.Dv FPE_... 489values for SIGFPE. 490.Pp 491The 492.Fa scp 493argument to a BSD-style handler points to an instance of struct 494sigcontext. 495.Pp 496The 497.Fa context 498argument to a POSIX SA_SIGINFO handler points to an instance of 499mcontext_t. 500.Sh ERRORS 501.Fn Sigaction 502will fail and no new signal handler will be installed if one 503of the following occurs: 504.Bl -tag -width Er 505.It Bq Er EFAULT 506Either 507.Fa act 508or 509.Fa oact 510points to memory that is not a valid part of the process 511address space. 512.It Bq Er EINVAL 513.Fa Sig 514is not a valid signal number. 515.It Bq Er EINVAL 516An attempt is made to ignore or supply a handler for 517.Dv SIGKILL 518or 519.Dv SIGSTOP . 520.El 521.Sh STANDARDS 522The 523.Fn sigaction 524function call is expected to conform to 525.St -p1003.1-90 . 526The 527.Dv SA_ONSTACK 528and 529.Dv SA_RESTART 530flags are Berkeley extensions, 531as are the signals, 532.Dv SIGTRAP , 533.Dv SIGEMT , 534.Dv SIGBUS , 535.Dv SIGSYS , 536.Dv SIGURG , 537.Dv SIGIO , 538.Dv SIGXCPU , 539.Dv SIGXFSZ , 540.Dv SIGVTALRM , 541.Dv SIGPROF , 542.Dv SIGWINCH , 543and 544.Dv SIGINFO . 545Those signals are available on most 546.Tn BSD Ns \-derived 547systems. 548The 549.Dv SA_NODEFER 550and 551.Dv SA_RESETHAND 552flags are intended for backwards compatibility with other operating 553systems. The 554.Dv SA_NOCLDSTOP , 555and 556.Dv SA_NOCLDWAIT 557.\" and 558.\" SA_SIGINFO 559flags are featuring options commonly found in other operating systems. 560.Sh SEE ALSO 561.Xr kill 1 , 562.Xr kill 2 , 563.Xr ptrace 2 , 564.Xr sigaltstack 2 , 565.Xr sigblock 2 , 566.Xr sigpause 2 , 567.Xr sigpending 2 , 568.Xr sigprocmask 2 , 569.Xr sigsetmask 2 , 570.Xr sigsuspend 2 , 571.Xr sigvec 2 , 572.Xr wait 2 , 573.Xr fpsetmask 3 , 574.Xr setjmp 3 , 575.Xr siginterrupt 3 , 576.Xr sigsetops 3 , 577.Xr tty 4
| 325invoke them, without restriction, from signal-catching functions: 326.Pp 327Base Interfaces: 328.Pp 329.Fn _exit , 330.Fn access , 331.Fn alarm , 332.Fn cfgetispeed , 333.Fn cfgetospeed , 334.Fn cfsetispeed , 335.Fn cfsetospeed , 336.Fn chdir , 337.Fn chmod , 338.Fn chown , 339.Fn close , 340.Fn creat , 341.Fn dup , 342.Fn dup2 , 343.Fn execle , 344.Fn execve , 345.Fn fcntl , 346.Fn fork , 347.Fn fpathconf , 348.Fn fstat , 349.Fn fsync , 350.Fn getegid , 351.Fn geteuid , 352.Fn getgid , 353.Fn getgroups , 354.Fn getpgrp , 355.Fn getpid , 356.Fn getppid , 357.Fn getuid , 358.Fn kill , 359.Fn link , 360.Fn lseek , 361.Fn mkdir , 362.Fn mkfifo , 363.Fn open , 364.Fn pathconf , 365.Fn pause , 366.Fn pipe , 367.Fn raise , 368.Fn read , 369.Fn rename , 370.Fn rmdir , 371.Fn setgid , 372.Fn setpgid , 373.Fn setsid , 374.Fn setuid , 375.Fn sigaction , 376.Fn sigaddset , 377.Fn sigdelset , 378.Fn sigemptyset , 379.Fn sigfillset , 380.Fn sigismember , 381.Fn signal , 382.Fn sigpending , 383.Fn sigprocmask , 384.Fn sigsuspend , 385.Fn sleep , 386.Fn stat , 387.Fn sysconf , 388.Fn tcdrain , 389.Fn tcflow , 390.Fn tcflush , 391.Fn tcgetattr , 392.Fn tcgetpgrp , 393.Fn tcsendbreak , 394.Fn tcsetattr , 395.Fn tcsetpgrp , 396.Fn time , 397.Fn times , 398.Fn umask , 399.Fn uname , 400.Fn unlink , 401.Fn utime , 402.Fn wait , 403.Fn waitpid , 404.Fn write . 405.Pp 406Realtime Interfaces: 407.Pp 408.Fn aio_error , 409.Fn clock_gettime , 410.Fn sigpause , 411.Fn timer_getoverrun , 412.Fn aio_return , 413.Fn fdatasync , 414.Fn sigqueue , 415.Fn timer_gettime , 416.Fn aio_suspend , 417.Fn sem_post , 418.Fn sigset , 419.Fn timer_settime . 420.Pp 421All functions not in the above lists are considered to be unsafe 422with respect to signals. That is to say, the behaviour of such 423functions when called from a signal handler is undefined. 424.Sh RETURN VALUES 425A 0 value indicated that the call succeeded. A \-1 return value 426indicates an error occurred and 427.Va errno 428is set to indicated the reason. 429.Sh EXAMPLES 430There are three possible prototypes the handler may match: 431.Bl -tag -offset indent -width short 432.It ANSI C: 433.Fd 434void handler(int); 435.It Traditional BSD style: 436.Fd 437void handler(int, int code, struct sigcontext *scp); 438.It POSIX SA_SIGINFO: 439.Fd 440void handler(int, siginfo_t *info, void *context); 441.El 442.Pp 443The handler function should match the SA_SIGINFO prototype if the 444SA_SIGINFO bit is set in flags. 445It then should be pointed to by the 446.Dv sa_siginfo 447member of 448.Dv struct sigaction . 449Note that you should not assign SIG_DFL or SIG_IGN this way. 450.Pp 451If the SA_SIGINFO flag is not set, the handler function should match 452either the ANSI C or traditional BSD prototype and be pointed to by 453the 454.Dv sa_handler 455member of 456.Dv struct sigaction . 457In pratice, 458.Fx 459always sends the three arguments of the latter and since the ANSI C 460prototype is a subset, both will work. 461The 462.Dv sa_handler 463member declaration in 464.Fx 465include files is that of ANSI C (as required by POSIX), 466so a function pointer of a BSD-style function needs to be casted to 467compile without warning. 468The traditional BSD style is not portable and since its capabilities 469are a full subset of a SA_SIGINFO handler, 470its use is deprecated. 471.Pp 472The 473.Fa sig 474argument is the signal number, one of the 475.Dv SIG... 476values from <signal.h>. 477.Pp 478The 479.Fa code 480argument of the BSD-style handler and the 481.Dv si_code 482member of the 483.Dv info 484argument to a SA_SIGINFO handler contain a numeric code explaning the 485cause of the signal, usually one of the 486.Dv SI_... 487values from 488<sys/signal.h> or codes specific to a signal, i.e. one of the 489.Dv FPE_... 490values for SIGFPE. 491.Pp 492The 493.Fa scp 494argument to a BSD-style handler points to an instance of struct 495sigcontext. 496.Pp 497The 498.Fa context 499argument to a POSIX SA_SIGINFO handler points to an instance of 500mcontext_t. 501.Sh ERRORS 502.Fn Sigaction 503will fail and no new signal handler will be installed if one 504of the following occurs: 505.Bl -tag -width Er 506.It Bq Er EFAULT 507Either 508.Fa act 509or 510.Fa oact 511points to memory that is not a valid part of the process 512address space. 513.It Bq Er EINVAL 514.Fa Sig 515is not a valid signal number. 516.It Bq Er EINVAL 517An attempt is made to ignore or supply a handler for 518.Dv SIGKILL 519or 520.Dv SIGSTOP . 521.El 522.Sh STANDARDS 523The 524.Fn sigaction 525function call is expected to conform to 526.St -p1003.1-90 . 527The 528.Dv SA_ONSTACK 529and 530.Dv SA_RESTART 531flags are Berkeley extensions, 532as are the signals, 533.Dv SIGTRAP , 534.Dv SIGEMT , 535.Dv SIGBUS , 536.Dv SIGSYS , 537.Dv SIGURG , 538.Dv SIGIO , 539.Dv SIGXCPU , 540.Dv SIGXFSZ , 541.Dv SIGVTALRM , 542.Dv SIGPROF , 543.Dv SIGWINCH , 544and 545.Dv SIGINFO . 546Those signals are available on most 547.Tn BSD Ns \-derived 548systems. 549The 550.Dv SA_NODEFER 551and 552.Dv SA_RESETHAND 553flags are intended for backwards compatibility with other operating 554systems. The 555.Dv SA_NOCLDSTOP , 556and 557.Dv SA_NOCLDWAIT 558.\" and 559.\" SA_SIGINFO 560flags are featuring options commonly found in other operating systems. 561.Sh SEE ALSO 562.Xr kill 1 , 563.Xr kill 2 , 564.Xr ptrace 2 , 565.Xr sigaltstack 2 , 566.Xr sigblock 2 , 567.Xr sigpause 2 , 568.Xr sigpending 2 , 569.Xr sigprocmask 2 , 570.Xr sigsetmask 2 , 571.Xr sigsuspend 2 , 572.Xr sigvec 2 , 573.Xr wait 2 , 574.Xr fpsetmask 3 , 575.Xr setjmp 3 , 576.Xr siginterrupt 3 , 577.Xr sigsetops 3 , 578.Xr tty 4
|