加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

如何编写看门狗定时器以重新启动Windows服务?

发布时间:2020-12-14 02:10:33 所属栏目:Windows 来源:网络整理
导读:我对有关 Windows服务的看门狗定时器的另一个问题的答案非常感兴趣(见 here).答案说: I have also used an internal watchdog system running in another thread. That thread looks at the main thread for activity like log output or a toggling event.
我对有关 Windows服务的看门狗定时器的另一个问题的答案非常感兴趣(见 here).答案说:

I have also used an internal watchdog system running in another thread. That thread looks at the main thread for activity like log output or a toggling event. If the activity is not seen then the service is considered hung and I shutdown the service.

In this case you can configure windows to auto-restart a stopped service and that might clear the problem (as long as it’s not an internal logic bug).

Also services I work with have text logs that are written to a log. In addition for services that are about to “sleep for a bit”,I log the time for the next wake up. I use MTAIL to watch a log for output.”

任何人都可以提供一些示例代码如何使用在另一个线程中运行的内部监视程序,因为我目前有一个任务来开发一个Windows服务,它将能够自动重启,以防它失败,挂断等.

我非常感谢你的帮助.

解决方法

在你正在观看的过程中,我不是一个将看门狗作为线程运行的忠实粉丝.这意味着如果整个过程由于某种原因而挂起,则看门狗将无法工作.

看门狗是从硬件世界中解脱出来的一个想法,他们做对了.尽可能简单地使用外部电路(因此可以证明它是正确的).典型的看门狗只是运行一个计时器,如果进程在计时器到期之前没有做某事(比如访问看门狗正在观看的内存位置),整个过程就被重置了.当看门狗被“踢”时,它将重启计时器.

启动监视程序的过程的行为保护该进程免于摘要终止.

我的建议是编写一个非常简单的独立程序,它只监视一个事件(比如修改文件更新时间).如果该事件未在所需时间内发生,则终止正在监视的进程(并让Windows重新启动它).

然后让您观看的程序定期重写该文件.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读