Recently I found some code which uses signal
:
286 static void sighandler( int signum )
287 {
288 alarmed = 1;
289 signal( signum,
Handling Signals
The call to signal establishes signal handling for only one occurrence of a signal. Before the signal-handling function is called, the library resets the signal so that the default action is performed if the same signal occurs again. Resetting signal handling helps to prevent an infinite loop if, for example, an action performed in the signal handler raises the same signal again. If you want your handler to be used for a signal each time it occurs, you must call signal within the handler to reinstate it. You should be cautious in reinstating signal handling. For example, if you continually reinstate SIGINT handling, you may lose the ability to interrupt and terminate your program.
The signal()
function defines the handling of the next received signal only, after which the default handling is reinstated. So it is necessary for the signal handler to call signal()
if the program needs to continue handling signals using a non-default handler.