Find the answer to your Linux question:
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 ...
  1. #1
    Just 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.

  2. #2
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    Can anyone guide me or show me references on how to properly set the time limit for child processes to execute?
    The 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:
    Code:
    man setrlimit
    If that man page is not installed on your system, google this:
    Code:
    man setrlimit Linux
    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
    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.

    Hope this helps.
    --
    Bill

    Old age and treachery will overcome youth and skill.

  3. #3
    Just 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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...