#include #include #include #include int main(int argc, char**argv) { pid_t pid = fork(); if(pid < 0) { abort(); } if(pid > 0) { /* P1 */ printf("[%d] I'm P1. My PPID=%d\n", getpid(), getppid()); } else { /* P2 */ sleep(1); pid = fork(); if( pid < 0) { abort(); } if(pid > 0) { /* P2 */ printf("[%d] I'm P2. My PPID=%d\n", getpid(), getppid()); } else { /* P3 */ sleep(1); pid = fork(); if( pid < 0) { abort(); } if(pid > 0) { /* P3 */ printf("[%d] I'm P3. My PPID=%d\n", getpid(), getppid()); } else { /* P4 */ printf("[%d] I'm P4. My PPID=%d\n", getpid(), getppid()); system("ps f"); } } } return EXIT_SUCCESS; }