8 summary b 211020 c 102120 d 122001 e 100212 445

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

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 defined 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

This note was uploaded on 09/02/2010 for the course ELECTRICAL 360 taught by Professor Schultz during the Spring '10 term at BYU.

Ask a homework question - tutors are online