一个看门狗的理解

yaxf999 yaxf999 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
下面这段代码,不知道怎么理解:

int Watching()
{
pid_t cpid, w;
int status;

do
{
cpid = fork();
if(cpid == - 1)
{
printf("fork error!\n");
exit(EXIT_FAILURE);
}

if(cpid == 0)
{
printf("Child PID is %ld\n", (long)getpid());
return 0;
}

w = waitpid(cpid, &status, WUNTRACED | WCONTINUED);
if(w == - 1)
{
perror("waitpid");
exit(EXIT_FAILURE);
}

if(WIFEXITED(status))
{
printf("exited, status=%d\n", WEXITSTATUS(status));
}
else if(WIFSIGNALED(status))
{
printf("killed by signal %d\n", WTERMSIG(status));
}
else if(WIFSTOPPED(status))
{
printf("stopped by signal %d\n", WSTOPSIG(status));
}
else if(WIFCONTINUED(status))
{
printf("continued\n");
}
}while(15 != WTERMSIG(status));

exit(EXIT_SUCCESS);

return 1;
}
有人能帮忙解释不?
...全文
评论 13
收藏 已收藏
分享
返回顶部
yaxf999
C语言 70,039 成员 243,237 内容