Find the answer to your Linux question:
Results 1 to 2 of 2
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Question How to limit or reset PIDs


    Say I have a C program that does:


    The system() call creates a new PID at each call. Therefore, when the maximum number of PIDs is reached, the ls command becomes <defunct> and eventually the system crashes.

    I tried also popen() but it is the same result.

    Is there a way of avoiding this behavior?


  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    This is when you need to wait on death-of-child events with wait() or waitpid(), inside your loop. That will remove the defunct pid from the process tree, otherwise the observed behavior is expected. The system() command does a fork/exec and each fork generates a new pid, as does popen(). Alternatively, you can use one of the exec...() functions, but then your root process will no longer exist. IE, using exec() without a fork will transform your current process into a new one, but using the same PID.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

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