I l @ ve RuBoard |
A signal is a condition that can be reported during program execution. It is represented by a positive integer. The raise() function sends, or raises , a signal, and the signal() function sets the response to a particular signal.
The standard provides the macros listed in Table F.8 to represent possible signals; an implementation can add further values. They can be used as arguments to raise() and signal() .
Macro | Description |
---|---|
SIGABRT | Abnormal termination, such as initiated by a call to abort() . |
SIGFPE | Erroneous arithmetic operation. |
SIGILL | Invalid function image (such as illegal instruction) detected . |
SIGINT | Interactive attention signal received (such as a DOS interrupt). |
SIGSEGV | Invalid access to storage. |
SIGTERM | Termination request sent to program. |
The signal() function takes as its second argument a pointer to a void function that takes an int argument. It also returns a pointer of the same type. A function invoked in response to a signal is termed a signal handler . The standard defines three macros fitting this prototype:
void (*funct)(int);
Table F.9 lists these macros.
Macro | Description |
---|---|
SIG_DFL | When used as an argument to signal() , along with a signal value, indicates that the default handling for that signal will occur. |
SIG_ERR | Used as a return value for signal() if it cannot return its second argument. |
SIG_IGN | When used as an argument to signal() , along with a signal value, indicates that the signal will be ignored. |
If a signal sig is raised and func points to a function (see signal() prototype in Table F.10), first, under most circumstances, signal(sig, SIG_DFL) is called to reset signal handling to the default, and then (*func)(sig) is called. The signal-handling function pointed to by func can terminate by executing a return statement or by calling abort() , exit() , or longjmp() .
Table F.10 lists the signal functions.
Prototype | Description |
---|---|
void (*signal(int sig, void (*func)(int)))(int); | Causes the function pointed to by func to be executed if signal sig is raised. If possible, returns func ; otherwise , returns SIG_ERR . |
int raise(int sig); | Sends the signal sig to the executing program; returns zero if successful, and non-zero otherwise. |
I l @ ve RuBoard |