对未处理的异常重新启动应用程序

对未处理的异常重新启动应用程序

本文介绍了对未处理的异常重新启动应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果程序崩溃,程序可能会自动重新启动?

Is it possible to have a program restart automatically if it crashes?

类似:


  1. 抛出未处理的异常

  2. 释放进程分配的所有资源。

  3. 重新启动并调用main。

我想为我正在处理的服务器应用程序执行此操作。如果客户端错过使用服务器,它可能会得到一个std :: bac_alloc异常,在这种情况下,我希望服务器只是重新启动,而不是崩溃和关闭,从而避免手动启动。

I would like this behavior for a server application I'm working on. If clients miss use the server it can get a std::bac_alloc exception, in which case I would like the server to simply restart instead of crashing and shutting down, thus avoiding manual startup.

推荐答案

我之前在Windows中通过从另一个程序运行所述程序通过win32 调用。其他程序然后等待监视进程退出,并再次调用其 CreateProcess()。通过在进程的句柄上执行,您可以等待进程退出作为 CreateProcess()调用的返回值之一。

I've done this before in Windows by running said program from another program via a win32 CreateProcess call. The other program then waits on the "monitored" process to exit, and calls its CreateProcess() again if it does. You wait for a process to exit by performing a WaitForSingleObject on the process' handle, which you get as one of the return values from your CreateProcess() call.

方法使监控过程自行关闭,子进程关闭。

You will of course want to program in some way to make the monitoring process shut itself and its child process down.

这篇关于对未处理的异常重新启动应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 09:08