一个看门狗的理解
下面这段代码,不知道怎么理解:
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;
}
有人能帮忙解释不?
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;
}
有人能帮忙解释不?
...全文
相关推荐
一个基于VC的看门狗程序源码
一个基于VC的看门狗程序源码 一个基于VC的看门狗程序源码
STM32的独立看门狗程序,亲测可用
STM32的独立看门狗程序,亲测可用。内有详细注释和说明文档,很好的参考资料。
有了看门狗就不会死机?
死机是指CPU的程序指针进入一个死循环,无法执行正常的程序流程。其外在表现常常是:正常功能丧失,按键无响应,显示凝固。单片机死机后,只有复全才能走出死循环,执行正常的程序流程。众所属知,克服死机的最有效手段是加看门狗(WatchDog)。
通用看门狗程序
通用的嵌入式看门狗程序源代码,实现程序的自动启动、调度和重复调用
STM32 看门狗
MiniSTM32 test5 watchdog 看门狗示例


