简体   繁体   English

如何指定程序可以在C ++中运行的最长时间

[英]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.

相关问题 如何限制生成的程序可以在C ++中使用的内存量 - How to limit the amount of memory a spawned program can use in C++ 如何在指定的时间内运行程序? - How to run a program for a specified amount of time? 每次在Visual C ++程序中抛出异常时,如何运行某些代码? - How can some code be run each time an exception is thrown in a Visual C++ program? 如何在c ++程序运行时隐藏控制台? - How I can hide the console during c++ program run-time? 如何将变量的值设置为大于 C++ 中的 unsigned long long 最大值的量? - How can I set value of a variable to an amount that is more than unsigned long long maximum value in C++? 如何在以下C程序中计算运行时内存和最大数据内存使用量 - How to calculate run time memory and maximum data memory usage in following c program 如何将C ++程序作为Simulink块运行? - How can I run a C++ program as a Simulink block? 用 C++ 编写的程序如何在多个 CPU 架构上运行? - How can a program written in C++ be run on multiple CPU architectures? 如何在linux上找到C ++程序的最大内存堆栈大小? (gnu编译器) - How can you find out the maximum size of the memory stack for a C++ program on linux? (gnu compiler) 如何在另一个C ++程序中运行C ++程序? - How to run a C++ program inside another C++ program?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM