一个看门狗的理解
下面这段代码,不知道怎么理解:
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;
}
有人能帮忙解释不?