Sends a signal to a process useful for debugging

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: interrupted by the arrival of the signal. Installing and using signal handlers can be quite subtle, and is the topic of the next three sections. 8.5.3 Receiving Signals When the kernel is returning from an exception handler and is ready to pass control to process Ô, it checks the set of unblocked pending signals (pending & ˜blocked). If this set is empty (the usual case), then 8.5. SIGNALS 427 code/ecf/alarm.c 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 #include "csapp.h" void handler(int sig) { static int beeps = 0; printf("BEEP\n"); if (++beeps < 5) Alarm(1); /* next SIGALRM will be delivered in 1s */ else { printf("BOOM!\n"); exit(0); } } int main() { Signal(SIGALRM, handler); /* install SIGALRM handler */ Alarm(1); /* next SIGALRM will be delivered in 1s */ while (1) { ; /* signal handler returns control here each time */ } exit(0); } code/ecf/alarm.c Figure 8.26: Using the alarm function to schedule periodic events. 428 the kernel passes contr...
View Full Document

Ask a homework question - tutors are online