如果父进程先结束,子进程不会自己结束
#include<stdio.h>
#include<stdlib.h>
#include<sys/wait.h>
int main(){
int a,b,c;
if(a = fork()){
printf("fork1---%ld\n",a);
int stat;
//等待子进程结束
pid_t child_pid = wait(&stat);
if(WIFEXITED(stat)){
printf("exited with code %d\n",WEXITSTATUS(stat));
}
}else{
printf("I'm child\n");
}
//int stat;
//pid_t child_pid = wait(&stat);
//if(WIFEXITED(stat)){
// printf("exited with code %d\n",WEXITSTATUS(stat));
//}
return 0;
}