void (*signal(sig, func))() void (*func)();
signal() is a simplified interface to the more general sigvec.2 facility. Programs that use signal() in preference to sigvec() are more likely to be portable to all systems.
A signal is generated by some abnormal event, initiated by a user at a terminal (quit, interrupt, stop), by a program error (bus error, etc.), by request of another program (kill), or when a process is stopped because it wishes to access its control terminal while in the background (see termio.4 Signals are optionally generated when a process resumes after being stopped, when the status of child processes changes, or when input is ready at the control terminal. Most signals cause termination of the receiving process if no action is taken; some signals instead cause the process receiving them to be stopped, or are simply discarded if the process has not requested otherwise. Except for the SIGKILL and SIGSTOP signals, the signal() call allows signals either to be ignored or to interrupt to a specified location. The following is a list of all signals with names as in the include file <signal.h>:
SIGHUP(1)hangup SIGINT(2)interrupt SIGQUIT(3)quit SIGILL(4)illegal SIGTRAP(5)trace SIGABRT(6)abort SIGEMT(7)emulator SIGFPE(8)arithmetic SIGKILL(9)kill(cannot SIGBUS(1)*bus SIGSEGV(1)*segmentation SIGSYS(1)*bad SIGPIPE(1)write SIGALRM(1)alarm SIGTERM(1)software SIGURG(1)+urgent SIGSTOP(1)**stop SIGTSTP(1)**stop SIGCONT(1)+continue SIGCHLD(2)+child SIGTTIN(2)**background SIGTTOU(2)**background 23+I/O SIGXCPU(2)cpu getrlimit.2 SIGXFSZ(2)file getrlimit.2 SIGVTALRM(2)virtual getitimer.2 SIGPROF(2)profiling getitimer.2 28+window SIGLOST(2)*resource lockd.8c SIGUSR1(3)user-defined SIGUSR2(3)user-defined
The starred signals in the list above cause a core image if not caught or ignored.
If func is SIG_DFL, the default action for signal sig is reinstated; this default is termination (with a core image for starred signals) except for signals marked with + or **. Signals marked with + are discarded if the action is SIG_DFL; signals marked with ** cause the process to stop. If func is SIG_IGN the signal is subsequently ignored and pending instances of the signal are discarded. Otherwise, when the signal occurs further occurrences of the signal are automatically blocked and func is called.
A return from the function unblocks the handled signal and continues the process at the point it was interrupted. Unlike previous signal facilities, the handler func remains installed after a signal has been delivered.
If a caught signal occurs during certain system calls, terminating the call prematurely, the call is automatically restarted. In particular this can occur during a read.2v or write.2v on a slow device (such as a terminal; but not a file) and during a wait.2v
The value of signal() is the previous (or initial) value of func for the particular signal.
After a fork.2v or vfork.2 the child inherits all signals. An execve.2v resets all caught signals to the default action; ignored signals remain ignored.
If func is SIG_IGN the signal is subsequently ignored and pending instances of the signal are discarded. Otherwise, when the signal occurs, func is called. Further occurrences of the signal are not automatically blocked. The value of func for the caught signal is reset to SIG_DFL before func is called, unless the signal is SIGILL or SIGTRAP.
A return from the function continues the process at the point at which it was interrupted. The handler func does not remain installed after a signal has been delivered.
If a caught signal occurs during certain system calls, causing the call to terminate prematurely, the call is interrupted. In particular this can occur during a read.2v or write.2v on a slow device (such as a terminal; but not a file) and during a wait.2v After the signal catching function returns, the interrupted system call may return a -1 to the calling process with errno set to EINTR.
signal() returns the previous action on success. On failure, it returns -1 and sets errno to indicate the error.
signal() will fail and no action will take place if one of the following occurs:
An attempt was made to ignore or supply a handler for SIGKILL or SIGSTOP.
The handler routine can be declared:
void handler(sig, code, scp, addr) int sig, code; struct sigcontext *scp; char *addr;
Here sig is the signal number; code is a parameter of certain signals that provides additional detail; scp is a pointer to the sigcontext structure (defined in <signal.h>), used to restore the context from before the signal; and addr is additional address information. See sigvec.2 for more details.
Created by unroff & hp-tools. © by Hans-Peter Bischof. All Rights Reserved (1997).
Last modified 21/April/97