N exit0 parent sends a sigkill signal to a child

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: W code/ecf/waitpid1.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" #define N 2 int main() { int status, i; pid_t pid; for (i = 0; i < N; i++) if ((pid = Fork()) == 0) exit(100+i); /* child */ /* parent waits for all of its children to terminate */ while ((pid = waitpid(-1, &status, 0)) > 0) { if (WIFEXITED(status)) printf("child %d terminated normally with exit status=%d\n", pid, WEXITSTATUS(status)); else printf("child %d terminated abnormally\n", pid); } if (errno != ECHILD) unix_error("waitpid error"); exit(0); } code/ecf/waitpid1.c Figure 8.15: Using the waitpid function to reap zombie children. 8.4. PROCESS CONTROL 413 code/ecf/waitpid2.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 26 27 28 #include "csapp.h" #define N 2 int main() { int status, i; pid_t pid[N+1], retpid; for (i = 0; i < N; i++) if ((pid[i] = Fork()) == 0) exit(100+i); /* child */ /* parent reaps N children in order */ i = 0; while ((retpid = waitpid(pid[i++], &status, 0)) > 0)...
View Full Document

Ask a homework question - tutors are online