/* Create lots of child processes, keep them busy, and have them report periodically. */ #include #define NUM_CHILDREN 50 #define NUM_PRINTS 20 #define NUM_DELAY_LOOPS 3000000 void main() { int i, j, pid, status; for(i=0; i < NUM_CHILDREN; i++) if ((pid = fork()) == 0) break; if (pid != 0) for(i=0; i < NUM_CHILDREN; i++) waitpid(-1, & status, 0); else { pid = getpid(); for (i=0; i < NUM_PRINTS; i++) { for (j=0; j < NUM_DELAY_LOOPS; j++) /* do nothing */ ; printf("Hello there from process %d.\n", pid); } } printf("Good-bye from process %d.\n", getpid()); }