Results 1 to 3 of 3
Hi,
Can anyone guide me or show me references on how to properly set the time limit for child processes to execute? I've tried to do this by creating a ...
- 01-31-2008 #1Just Joined!
- Join Date
- Nov 2007
- Posts
- 2
How to properly set a time limit for a child process
Hi,
Can anyone guide me or show me references on how to properly set the time limit for child processes to execute? I've tried to do this by creating a helper function that kills the process with the child pid. My problem with this is the child sometimes dies before the kill is called by the helper function and the pid by this time gets assigned to another process which gets killed instead. I'm considering using a handler for SIGCHLD that would remove the timer if the function is called before it times out or a pipe to signal from child to parent that it's dying. I wonder if you have any better ideas.
I might be going through a very convoluted method when there's a simpler way to do this. If you can help me in any way, it would be much appreciated.
Thanks.
- 01-31-2008 #2The place to do that is in the child process, just after the fork() but before the exec(). For information on setting limits for a process, do this at the command line:Can anyone guide me or show me references on how to properly set the time limit for child processes to execute?
If that man page is not installed on your system, google this:Code:man setrlimit
Code:man setrlimit Linux
You've suggested a couple of ways around this, but the best solution is far simpler. Even after exiting, your child process will keep its process number (so no new process can use it) until you do a wait() or waitpid() which indicates that the process has gone away. That's exactly what a zombie process is: one which has exited, but whose parent process has not yet received notification (through wait() or waitpid()) that the process has died, and what its exit status was.the child sometimes dies before the kill is called by the helper function and the pid by this time gets assigned to another process which gets killed instead
Hope this helps.--
Bill
Old age and treachery will overcome youth and skill.
- 02-01-2008 #3Just Joined!
- Join Date
- Nov 2007
- Posts
- 2
Hi Bill,
Thanks a lot for your help
This is exactly the kind of information I was looking for.
Thanks.


Reply With Quote