signal(S) 6 January 1993 signal(S) Name signal - set a signal action Syntax cc . . . -lc #include <signal.h> void (*signal (sig, func))() int sig; void (*func)(); Description The signal routine is not considered to be completely reliable for some applications. Therefore, it is strongly recommended that the sigaction routine, which supersedes the signal routine, be used in all new applications instead. The signal and the sigaction routines should never be used in the same application to control the same signal as this results in undefined behavior of the sigaction routine. The signal rou- tine is still included largely for backward compatibility. The signal routine allows the calling process to choose one of three ways to handle the receipt of a specified signal. The argument sig specifies the particular signal and the argument func specifies the course of action to be taken. The sig argument can be assigned any one of the following values except SIGKILL and SIGSTOP: _________________________________________________________________________ Signal ValueDescription XPG 3POSIX ANSI _________________________________________________________________________ SIGHUP 01 hangup + + SIGINT 02 interrupt + + + SIGQUIT 03[1]quit + + SIGILL 04[1]illegal instruction (not reset when caught) + + + SIGTRAP 05[1]trace trap (not reset when caught) SIGIOT 06[1]IOT instruction SIGABRT 06[1]used by abort, replaces SIGIOT + + + SIGEMT 07[1]EMT instruction SIGFPE 08[1]floating point exception + + + SIGKILL 09 kill (cannot be caught or ignored) + + SIGBUS 10[1]bus error SIGSEGV 11[1]segmentation violation + + + SIGSYS 12[1]bad argument to system call SIGPIPE 13 write on a pipe with no one to read it + + SIGALRM 14 alarm clock + + SIGTERM 15 software termination signal + + + SIGUSR1 16 user-defined signal 1 + + SIGUSR2 17 user-defined signal 2 + + SIGCLD 18[3]death of a child SIGCHLD 18[3]synonym for SIGCLD SIGPWR 19[3]power fail SIGWINCH 20 window change SIGPOLL 22[4]selectable event pending SIGSTOP 23[2]sendable stop signal not from tty + + SIGTSTP 24[2]stop signal from tty + + SIGCONT 25[2]continue a stopped process + + SIGTTIN 26[2]background tty read attempt + + SIGTTOU 27[2]background tty write attempt + + SIGVTALRM28 virtual timer alarm SIGPROF 29 profile alarm The func argument is assigned one of the following three values: SIG_DFL, SIG_IGN, or an address of a function defined by the user. SIG_DFL, and SIG_IGN, are defined in the header file <signal.h>. Each is a macro that expands to a constant expression of type pointer to function returning void, and having a unique value that does not match a declar- able function. The actions prescribed by the values of the func argument are as follows: SIGDFL --execute default signal action Upon receipt of the signal specified by sig, the receiving pro- cess will take the default action. The default action usually results in the termination of the process with all of the conse- quences outlined in exit(S). Those signals with a [1] or a [2] are exceptions to this rule. Their default behavior is described in the corresponding Note section. SIGIGN --ignore signal Upon receipt of the signal specified by sig, the signal is ignored. Note: the SIGKILL and SIGSTOP signals cannot be ignored. signal-catching function --execute user-defined action Upon receipt of the signal sig, the receiving process executes the signal-catching function pointed to by func. The signal num- ber sig is passed as the only argument to the signal-catching function. Additional arguments are passed to the signal-catching function for hardware-generated signals. Before entering the signal-catching function, the value of func for the caught signal is set to SIGDFL unless the signal is SIGILL, SIGTRAP, or SIGPWR. Upon return from the signal-catching function, the receiving pro- cess resumes execution at the point it was interrupted. The signal catching function is not executed during certain slow processes even though a signal has been caught. Slow processes are considered to be a read(S), a write(S,) an open(S), or an ioctl(S) system call on a slow device (like a terminal; but not a file), a pause(S) routine, or during a wait(S) routine that does not return immediately due to the existence of a previously stopped or zombie process. Then the interrupted system call may return a -1 to the calling process with errno set to EINTR. The signal routine does not catch an invalid function argument, func, and results are undefined when an attempt is made to exe- cute the function at the bad address. Note: The SIGKILL and SIGSTOP signals cannot be caught. A call to signal cancels a pending signal sig except for a pending SIG- KILL or SIGSTOP signal. Return value Upon successful completion, signal returns the previous value of func for the specified signal sig. Otherwise, a value of SIG_ERR is returned and errno is set to indicate the error. SIG_ERR is defined in the include file <signal.h>. Diagnostics If the following condition occurs, the signal routine returns a value of SIG_ERR in func and sets errno to the corresponding value: [EINVAL] The value of the sig argument is an invalid or unsupported sig- nal number, or an attempt was made to catch a signal that can- not be caught or to ignore a signal that cannot be ignored. Note [1] If SIGDFL is assigned for these signals, in addition to the process being terminated, a ``core image'' is constructed in the current working directory of the process, if the following conditions are met: The effective user ID and the real user ID of the receiving pro- cess are equal. An ordinary file named core exists and is writable or can be cre- ated. If the file must be created, it has the following proper- ties: + a mode of 0666 modified by the file creation mask (see umask(S)) + a file owner ID that is the same as the effective user ID of the receiving process + a file group ID that is the same as the effective group ID of the receiving process. [2] For the signals SIGSTOP, SIGTSTP, SIGTTIN, and SIGTTOU the default action is to stop the process rather than to terminate the process. The distinction is that a stopped process can be started again with a SIGCONT whereas a terminated process cannot be restarted under any circumstance. For the SIGCONT signal, the default action is to continue the process if it is stopped, otherwise it is ignored. [3] For the signals SIGCLD and SIGPWR, func is, again, assigned one of three values: SIG_DFL, SIG_IGN, or a function address. The actions prescribed by these values are: SIGDFL --ignore signal The signal is to be ignored. SIGIGN --ignore signal The signal is to be ignored. Also, if sig is SIGCLD, the calling process's child processes does not create zombie processes when they terminate (see exit(S)). function address --catch signal If the signal is SIGPWR, the action to be taken is the same as that described above for func equal to function address. The same is true if the signal is SIGCLD with one exception: while the process is executing the signal-catching function, any received SIGCLD signals are ignored. (This is the default action.) In addition, SIGCLD affects the wait, waitpid, and exit system calls as follows: wait If the func value of SIGCLD is set to SIGIGN and a wait is executed, the wait blocks until all of the calling process's child processes terminate; it then returns a value of -1 with errno set to ECHILD. waitpid If the func value of SIGCLD is set to SIGIGN and a waitpid is executed, the waitpid blocks until all of the calling process's child processes terminate; it then returns a value of -1 with errno set to ECHILD. However, if the WNOHANG option is speci- fied, waitpid does not block. exit If in the exiting process's parent process the func value of SIGCLD is set to SIGIGN, the exiting process does not create a zombie process. When processing a pipeline, the shell makes the last process in the pipeline the parent of the preceding processes. A process that may be piped into in this manner (and thus become the parent of other pro- cesses) should take care not to set SIGCLD to be caught. [4] SIGPOLL is issued when a file descriptor corresponding to a STREAMS (see Intro(S)) file has a ``selectable'' event pending. A process must specifically request that this signal be sent using the I_SETSIG ioctl call. Otherwise, the process never receives SIGPOLL. SIGPOLL is defined to have a value of 20 if used in cross-compiling for XENIX. See also sigaction(S), sigprocmask(S), sigpending(S), sigsuspend(S), sigset(S), sigsetv(S), sigsetjmp(S), Intro(S), kill(S), pause(S), ptrace(S), wait(S), kill(C) Standards conformance signal is conformant with: AT&T SVID Issue 2; X/Open Portability Guide, Issue 3, 1989; and ANSI X3.159-1989 Programming Language -- C.