69,382
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(void)
{
pid_t pid = fork();
int status;
if (pid == -1)
printf("fork process error\n");
else if (pid == 0)
{
printf("I am a child process, my processId is:%d\n", getpid());
_exit(0);
}
else
{
pid_t wPid = waitpid(-1, &status, WNOHANG);
if (wPid > 0)
{
if (WIFEXITED(status))
{
if (WEXITSTATUS(status) == 0)
{
printf("I am a father process, my processId is:%d\n", getpid());
}
}
}
}
return 0;
}