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. 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?
Bit of a brute-force version, but... save/get the handle of the started programm/process, start a timer and kill the other process after the timer has expired?
2 solutions that comes to mind.
1- Send the duration to the second program via the command line and manage the duration internally in the 2nd exe. 2- Create a timer in the first exe and when the timer is triggered kill the 2nd process.
Max.
In general, it can't be done using standard c++ - you will have to use whatever scheduling functions your operating system (which you haven't specified) provides.
精彩评论