This preview shows page 1. Sign up to view the full content.
Unformatted text preview: f a signal */ exit(0); } code/ecf/sigint1.c Figure 8.27: A program that catches a SIGINT signal. The handler function is deﬁned in lines 3–7. The main routine installs the handler in lines 12–13, and then goes to sleep until a signal is received (line 15). When the SIGINT signal is received, the handler runs, prints a message (line 5) and then terminates the process (line 6). Practice Problem 8.7:
Write a program, called snooze, that takes a single command line argument, calls the snooze function from Problem 8.5 with this argument, and then terminates. Write your program so that the user can interrupt the snooze function by typing ctrl-c at the keyboard. For example: unix> ./snooze 5 Slept for 3 of 5 secs. unix> User hits crtl-c after 3 seconds 8.5.4 Signal Handling Issues
Signal handling is straightforward for programs that catch a single signal and then terminate. However, subtle issues arise when a program catches multiple signals. 430 CHAPTER 8. EXCEPTIONAL CONTROL FLOW ¯ ¯ Pending signals can be blocked. Unix signal handlers typically block pending signals of the type currently being processed by the handler. For example, suppose a process has caugh...
View Full Document