[英]How to specify a maximum amount of time a program can run in C++
In my C++ program, I will start other programs with exec. 在我的C ++程序中,我将使用exec启动其他程序。 However, I want to be able to specify a maximum amount of time that the programs can run. 但是,我希望能够指定程序可以运行的最长时间。 How can that be done? 怎么办?
Is setrlimit the right thing to use? setrlimit是正确使用的东西吗?
蛮力的版本,但是...保存/获取已启动程序/进程的句柄,启动计时器并在计时器到期后终止其他进程?
2 solutions that comes to mind. 我想到了2个解决方案。
1- Send the duration to the second program via the command line and manage the duration internally in the 2nd exe. 1-通过命令行将持续时间发送到第二个程序,并在第二个exe内部管理持续时间。 2- Create a timer in the first exe and when the timer is triggered kill the 2nd process. 2-在第一个exe中创建一个计时器,并在触发计时器后杀死第二个进程。
Max. 最大。
通常,这不能使用标准c ++来完成-您将不得不使用操作系统(未指定)提供的任何调度功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.