如何在 Windows 上重新加载崩溃的进程

发布于 2024-07-14 23:49:25 字数 99 浏览 5 评论 0原文

如何在 Windows 上重新加载崩溃的进程? 当然,我可以运行自定义的监控Win服务进程。 但是,例如Firefox:它似乎没有安装这样的东西,但它仍然可以在崩溃时自行重新启动。

How to reload a crashed process on Windows? Of course, I can run a custom monitoring Win service process. But, for example, Firefox: it doesn't seem to install such a thing, but still it can restart itself when it crashes.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

早茶月光 2024-07-21 23:49:25

在 Vista 及更高版本上,您可以使用 RegisterApplicationRestart API 自动重新启动当它崩溃或挂起时。

在 Vista 之前,您需要有一个顶级异常过滤器来执行重新启动,但请注意,在受损进程内运行代码并不完全安全或可靠。

On Vista and above, you can use the RegisterApplicationRestart API to automatically restart when it crashes or hangs.

Before Vista, you need to have a top level exception filter which will do the restart, but be aware that running code inside of a compromised process isn't entirely secure or reliable.

黑凤梨 2024-07-21 23:49:25

每次您打开选项卡或单击链接或执行某些其他操作时,Firefox 都会不断地将其状态保存到硬盘。 它还保存了一个标志,表示它已安全关闭。

启动时,它会读回所有内容,并能够根据该信息“恢复”。

Firefox constantly saves its state to the hard disk, every time you open a tab or click a link, or perform some other action. It also saves a flag saying it shut down safely.

On startup, it reads this all back, and is able to "restore" based on that info.

魔法少女 2024-07-21 23:49:25
  • 结构化异常处理 (SEH)允许您捕获程序崩溃并在发生时执行某些操作。
    请参阅:__try 和 __ except
    不过,SEH 可能非常危险,并且可能会导致您的程序挂起。 请参阅本文了解更多信息。

  • 如果您将程序编写为 NT 服务,则可以将第一个、第二个及后续失败操作设置为“重新启动服务”。

    如果

  • 对于 Windows 2008 服务器以及 Windows Vista 和 Windows 7,您可以使用 Win32 API RegisterApplicationRestart

请参阅 我的回答,了解有关处理不同类型的程序崩溃的更多信息。

  • Structured exception handling (SEH) allows you to catch program crashes and to do something when it happens.
    See: __try and __except
    SEH can be very dangerous though and could lead to your program hanging instead. Please see this article for more information.

  • If you write your program as an NT service then you can set the first, second and subsequent failure actions to "Restart the service".

  • For Windows 2008 server and Windows Vista and Windows 7 you can use the Win32 API RegisterApplicationRestart

Please see my answer here for more information about dealing with different types of program crashes.

七月上 2024-07-21 23:49:25

如果我没记错的话,Windows 至少实现了 POSIX 的某些子集,因此“必须”具有信号接口(例如 SIGKILL、SIGSEGV、SIGQUIT 等)。

我从来没有这样做过,但在 Linux 上,但你可以尝试使用 signal() (signal.h) 设置意外终止陷阱。
从文档的快速扫描来看,在处理信号时似乎可以做的事情很少,甚至可能启动一个新进程也在禁止列表中。

现在我已经考虑过了,我可能会选择主/工作模式,非常简单的父线程,除了生成工作线程(执行所有 UI/其他操作)之外什么也不做。 如果它没有设置特定的“我现在要死了”位但仍然死掉(父进程总是收到生成的进程死掉的消息/通知),那么 master 会重新生成工作进程。 主题是让master非常简单,并且很难因为自己的bug而死掉。

If I recall correctly Windows implements at least some subset of POSIX and so "must" have the signal interface (things like SIGKILL, SIGSEGV, SIGQUIT etc.).

I've never done this but on linux, but you could try setting the unexpected termination trap with signal() (signal.h).
From quick scan of docs it seems that very few things can be done while handling signal, it may be possible that even starting a new process is on forbidden list.

Now that I've thought about it, I'd probably go with master/worker pattern, very simple parent thread that does nothing but spawns the worker (that does all the UI / other things). If it does not set a specific "I'm gonna die now" bit but still dies (parent process always gets message / notification that spawned process died) then master respawns the worker. The main theme is keep master very simple and hard to die due to own bugs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文