00 678 728 728 729 1673 1718 2128 2130 2668

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: ; bar(); } void bar(void) { if (error2) longjmp(buf, 2); } code/ecf/setjmp.c Figure 8.33: Nonlocal jump example. This example shows the framework for using nonlocal jumps to recover from error conditions in deeply nested functions without having to unwind the entire stack. 440 CHAPTER 8. EXCEPTIONAL CONTROL FLOW code/ecf/restart.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 #include "csapp.h" sigjmp_buf buf; void handler(int sig) { siglongjmp(buf, 1); } int main() { Signal(SIGINT, handler); if (!sigsetjmp(buf, 1)) printf("starting\n"); else printf("restarting\n"); while(1) { Sleep(1); printf("processing...\n"); } exit(0); } code/ecf/restart.c Figure 8.34: A program that uses nonlocal jumps to restart itself when the user types ctrl-c. 8.7. TOOLS FOR MANIPULATING PROCESSES beginning of the main program. When we ran the program on our system, we got the following output: unix> ./restart starting processing... processing... restarting processing... restarting processing... 441 user hits...
View Full Document

Ask a homework question - tutors are online