#include #include #include #include #include int main(void) { /* int n = 4; for (int i = 0; i < 10 ; i++) { pid_t pid1 = fork(); printf("PID:%d n:%d &n:%d\n", pid1, n, &n); } */ pid_t pid = fork(); if (pid == 0) { printf("PID1: %d\n", getpid()); } else { sleep(3); printf("PPID: %d\n", getpid()); } if (pid != 0) { sleep(3); kill(pid, SIGKILL); wait(NULL); } pid_t pid_2 = fork(); if (pid_2 == 0) { printf("PID2: %d\n", getpid()); } else { printf("PPID: %d\n", getpid()); } if (pid == 0) { sleep(3); kill(getppid(), SIGKILL); } return 0; }