进程参考代码
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <sys/types.h> 4 #include <unistd.h> 5 #include <pwd.h> 6 #include <sys/wait.h> 7 8 int main(void) 9 { 10 pid_t pid = fork(); 11 int status; 12 if(pid== -1) 13 { 14 printf("fork failed\n"); 15 return 0; 16 } 17 if(pid==0) 18 { 19 exit(0); 20 } 21 else 22 { 23 printf("parent process start\n"); 24 wait(&status); 25 sleep(100); 26 // printf("status =%d\n",WEXITSTATUS(status)); 27 printf("parent process end\n"); 28 return 0; 29 } 30 31 return 0; 32 }