This preview shows page 1. Sign up to view the full content.
Unformatted text preview: intf("control should never reach here!\n"); exit(0); } /* parent sends a SIGKILL signal to a child */ Kill(pid, SIGKILL); exit(0); } code/ecf/kill.c Figure 8.25: Using the kill function to send a signal to a child. not this call to alarm cancelled it), or 0 if there were no pending alarms. Figure 8.26 shows a program called alarm that arranges to be interrupted by a SIGALRM signal every second for ﬁve seconds. When the sixth SIGALRM is delivered it terminates. When we run the program in Figure 8.26, we get the following output: a “BEEP” every second for ﬁve seconds, followed by a “BOOM” when the program terminates.
unix> ./alarm BEEP BEEP BEEP BEEP BEEP BOOM! Notice that the program in Figure 8.26 uses the signal function to install a signal handler function (handler) that is called asynchronously, interrupting the inﬁnite while loop in main, whenever the process receives a SIGALRM signal. When the handler function returns, control passes back to main, which picks up where it was...
View Full Document