signal() defines how the receipt of a signal is to be subsequently handled.
sig may be any signal defined by the system, except SIGKILL and SIGSTOP (see signal.h ). func () defines the signal action. The following values are possible: SIG_DFL (default signal handling)
SIG_IGN (ignore the signal)
Address of a signal-handling function (also called a signal handler) In this case, the system adds the signal sig to the signal mask of the calling process before the signal handler is executed. On exiting the signal-handler, the system restores the signal mask of the calling process to the existing state before the signal was received.
If func () points to a function, the following steps are performed in sequence when a signal occurs: An equivalent of the following signal function is executed: signal( sig, SIG_DFL);
If the value of sig in this example is SIGILL , a reset to SIG_DFL occurs. An equivalent of the following function is executed next: ( *func )( sig );
The signal-handling function func () may be terminated by a return statement or by an abort() , exit() , or longjmp() function. If func () executes a return statement and the value of sig is SIGFPE , SIGILL or SIGDVZ , the behavior is undefined. Otherwise, the program will resume execution at the point it was interrupted. If a signal occurs without abort() , kill() or raise() being called, the behavior is undefined if the signal handler calls an X/Open-conformant library function other than one of those listed in the table under sigaction() or if an object of static storage duration other than a variable of type volatile sig_atomic_t is accessed. If such a call fails, the value of errno is indeterminate. At program startup, the equivalent of the following function is executed for some signals: signal( sig, SIG_IGN);
An equivalent of the following function is executed for all other signals (see exec ): signal( sig, SIG_DFL);
The functions sigset() , sighold() , sigignore() , sigpause() and sigrelse() simplify signal management for application processes. sigset() is used to modify signal handling. sig indicates the signal, which can be any one except SIGKILL and SIGSTOP . disp defines the handling of the signal, which can be SIG_DFL , SIG_IGN or the address of a signal-handling routine. If sigset() is used and disp is the address of a signal-handling routine, the system adds the signal sig to the signal mask of the calling process before the signal-handling routine is executed. When execution of the signal-handling routine terminates, the system resets the signal mask of the calling process to the status it had before the signal was received. If sigset() is used and disp equals SIG_HOLD , then sig is added to the signal mask of the calling process, and the signal handling remains unchanged.
sighold() adds sig to the signal mask of the calling process.
sigrelse() removes sig from the signal mask of the calling process.
sigignore() sets the handling of sig to SIG_IGN .
sigpause() removes sig from the signal mask of the calling process and deactivates the calling process until a signal is received.
If one of the above functions is used to set the handling of SIGCHLD to SIG_IGN , the child processes of the calling process will not generate any zombie processes when they are terminated. If the calling process waits for its child processes consecutively, it blocks until all its child processes are terminated. The value -1 is then returned and errno contains the error ID ECHILD (see wait() , waitid() , waitpid() ). |