#include #include #include #include #include #include int main() { int p, s; p = fork(); if (p == 0) { int t; srandomdev(); t = random() % 10 + 5; printf("%d will wait for %d seconds\n", getpid(), t); sleep(t); printf("%d awake again\n", getpid()); exit(0); } p = fork(); if (p == 0) { int t; srandomdev(); t = random() % 10 + 5; printf("%d will wait for %d seconds\n", getpid(), t); sleep(t); printf("%d awake again\n", getpid()); exit(0); } p = fork(); if (p == 0) { int t; srandomdev(); t = random() % 10 + 5; printf("%d will wait for %d seconds\n", getpid(), t); sleep(t); printf("%d awake again\n", getpid()); exit(0); } p = wait(& s); printf("%d terminated status ~ %d\n", p, s); p = wait(& s); printf("%d terminated status ~ %d\n", p, s); p = wait(& s); printf("%d terminated status ~ %d\n", p, s); printf("%d main thread finished\n", getpid()); }