When a timer interrupt occurs the operating system

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: while ((pid = waitpid(-1, NULL, 0)) > 0) printf("Handler reaped child %d\n", (int)pid); if (errno != ECHILD) unix_error("waitpid error"); Sleep(2); return; } int main() { int i, n; char buf[MAXBUF]; pid_t pid; Signal(SIGCHLD, handler2); /* sigaction error-handling wrapper */ /* parent creates children */ for (i = 0; i < 3; i++) { pid = Fork(); if (pid == 0) { printf("Hello from child %d\n", (int)getpid()); Sleep(1); exit(0); } } /* parent waits for terminal input and then processes it */ if ((n = read(STDIN_FILENO, buf, sizeof(buf))) < 0) unix_error("read error"); printf("Parent processing input\n"); while (1) ; exit(0); } code/ecf/signal4.c Figure 8.32: signal4: A version of Figure 8.29 that uses our Signal wrapper to get portable signalhandling semantics. 438 returns a 0. #include <setjmp.h> CHAPTER 8. EXCEPTIONAL CONTROL FLOW void longjmp(jmp buf env, int retval); void siglongjmp(sigjmp buf env, int retval); never returns) The longjmp function restores the stack context from the env buffer and then triggers a return from the most recent setjmp call that initialized env. The setjmp then returns with the nonzero return val...
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