问题描述
由于某些限制,我试图编写一个使用看门狗的通知服务,我必须不在主进程中而是在该进程的子进程中使用sd_event_loop。问题在于,当事件循环在子进程中运行时,看门狗超时。这是我的代码:
// Not working
int main(int argc,char ** argv) {
sd_event *event;
pid_t child_pid = fork();
if (child_pid == 0) {
sd_event_source *src = NULL;
notify_start("READY=1\n"
"STATUS=Daemon is running",NOTIFY_STOPPING);
sd_event_default(&event);
sd_event_set_watchdog(event,true);
sd_event_loop(event);
exit(0);
} else {
waitpid(child_pid,NULL,0);
}
return 0;
}
// Working
int main(int argc,char ** argv) {
sd_event *event;
pid_t child_pid = 0;
if (child_pid == 0) {
sd_event_source *src = NULL;
notify_start("READY=1\n"
"STATUS=Daemon is running",0);
}
return 0;
}
日志中的错误是:
Sep 21 18:08:06 ubuntu systemd[1]: test.service: Watchdog timeout (limit 1min)!
配置单元文件如下:
Type=notify
Restart=always
RestartSec=0
ExecStart=/etc/tmp/test
WatchdogSec=1min
NotifyAccess=all
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)