1 #include2 #include 3 #include 4 5 6 int main(void) 7 { 8 pid_t pid; 9 pid = fork();10 if(pid < 0){11 perror("fail to fock!\n");12 exit(-1);13 }14 else if(pid == 0){15 /*子进程*/16 printf("Sub-process,PID: %u,PPID: %u\n",getpid(),getppid());17 }18 else{19 /*父进程*/20 printf("Parent,PID: %u,Sub-process PID: %u\n",getpid(),pid);21 sleep(2);22 }23 return 0;24 }