#include #include #include #include #include void draw(const char *txt); int main() { time_t curtime = times(NULL); int pid = fork(); if (pid < 0) { perror("Fork failed"); return -1; } if (pid != 0) { printf("==> Parent: Child PID=%d\n", pid); srand(curtime); draw("Heads"); waitpid(pid, NULL, 0); printf("========\n"); } else { printf("==> Child\n"); draw("Tails"); srand(curtime + 12345678); } return 0; } void draw(const char *txt) { for (int i = 0; i < 10; ++i) { printf("%s\n", txt); int r = rand() % 2000000 + 1; usleep(r); } }