23,120
社区成员
发帖
与我相关
我的任务
分享
#include<stdio.h>
#include<sys/wait.h>
#include<unistd.h>
int main(int argc,char* argv[])
{
printf("before fork~\n");
if(fork() < 0)
{
printf("error\n");
}
else if(fork() > 0)
{
printf("this is parent~\n");
int stat;
pid_t t=wait(&stat);
if(WIFEXITED(stat))
printf("正常终止~\n");
}
else
{
printf("this is children~\n");
sleep(9);
}
return 0;
}
#include<stdio.h>
#include<sys/wait.h>
#include<unistd.h>
int main(int argc,char* argv[])
{
printf("before fork~\n");
pid_t pid = fork();
// if(fork() < 0)
if(pid < 0)
{
printf("error\n");
}
// else if(fork() > 0)
else if(pid > 0)
{
printf("this is parent~\n");
int stat;
pid_t t=wait(&stat);
if(WIFEXITED(stat))
printf("正常终止~\n");
}
else
{
printf("this is children~\n");
sleep(9);
}
return 0;
}