如何在不关闭正在运行的程序的情况下顺利重启c ++程序? [英] How to smooth restart a c++ program without shut down the running program?

查看:150
本文介绍了如何在不关闭正在运行的程序的情况下顺利重启c ++程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个服务器程序,应该每天全天运行.如果我想更改它的某些参数,除了关闭然后重新启动,有什么办法吗?

解决方案

有很多方法可以做到这一点,包括但几乎不限于:

  1. 您可以在单独的文件中维护参数,以便程序定期检查该文件并更新其内部信息.

  2. 类似于(1),但是您可以向应用程序发送某种信号,以使其立即重新读取文件.

  3. 您可以执行(1)或(2),但使用共享内存而不是配置文件.

  4. 您可以将程序放在IPC对话的服务器端,以便客户端可以打开与之的连接以提供新的参数.从简单的消息队列到功能完善的HTTP服务器以及相关页面,一应俱全.

当然,所有这些趋向于需要在程序中进行大量工作才能使其查找新信息.

做出决定时应考虑到这一点.到目前为止,要实现的 quickest 解决方案是(干净地)在晚上11:55左右终止该进程,然后立即重新启动它.这很简单,因为您的代码可能已经具有在启动时加载信息的能力,所以这可能是简单的cron单行代码.

有些人把懒惰说成是的事情,但并非总是这样:-)

I have a server program which should run full time a day. If I want to change some parameters of it, Is there any way rather than shut down then restart way?

解决方案

There are quite a few ways of doing this, including, but almost certainly not limited to:

  1. You can maintain the parameters in a separate file so that the program will periodically check that file and update its internal information.

  2. Similar to (1) but you can send some sort of signal to the application to get it to immediately re-read the file.

  3. You can do either (1) or (2) but using shared memory rather than a configuration file.

  4. You can have your program sit at the server end of an IPC conversation, so that a client can open up a connection to it to provide new parameters. Anything from a simple message queue to a full-blown HTTP server and associated pages.

Of course, all of these tend to need a fair amount of work in your program to get it to look for the new information.

You should take that into account when making your decision. By far the quickest solution to implement is to just (cleanly) kill off the process at something like 11:55pm then immediately restart it. It's simpler because your code probably already has the ability to load the information on startup, so this could be a simple cron one-liner.

Some people speak of laziness as a bad thing but that's not always the case :-)

这篇关于如何在不关闭正在运行的程序的情况下顺利重启c ++程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆