Reputation: 11293
Is it possible to kill process created by System? As far, as I know, System uses fork() function to create a new process. I want to track the running time of the process called (forked it before calling system) and kill it if it exceeds running time limit. Will the child created by system() be killed as well if I kill the child created by my main process?
this is not the actual code but may give an idea what I am talking about.
int pid = fork();
if(pid == 0)
{
system("./veryLongProgram");
}
else
{
// calculate time elapsed and kill on long execution time
}
I would also prefer if I could use CPU time limit BUT I don't want my child process to sleep. If it does - it may stay in such state for a very long time. Is it possible to interupt any sleep, pause or whatever intentionally called by the program called? That would be ideal. Or maybe I can check if my process is sleeping (in such case I also have to make sure it did it on purpose and wasn't paused because of some printing or whatever)?
Upvotes: 0
Views: 808
Reputation: 60007
exec
instead of systemSIGARLM
signal. Upon receipt use the kill
system call to kill the child. Use the alarm
function to set the alarm.wait
system call to wait until the child dies off naturally or due to receiving the system call.You can make it a little less harsh but first sending TERM
signal first and giving the child an opportunity to tidy up before sending KILL
signal.
Upvotes: 2