Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7006191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:26:46+00:00 2026-05-27T21:26:46+00:00

Even though the linux man page for wait 1 explains very well that you

  • 0

Even though the linux man page for wait 1 explains very well that you need to wait() for child processes for them no to turn into zombies, it does not tell why at all.

I planned my program (which is my first multithreaded one, so excuse my naivity) around a for(;;)ever loop that starts child processes which get exec()ed away and are sure to terminate on their own.

I cannot use wait(NULL) because that makes parallel computation impossible, therefore I’ll probably have to add a process table that stores the child pids and have to use waitpid – not immideately, but after some time has passed – which is a problem, because the running time of the children varies from few microseconds to several minutes. If I use waitpid too early, my parent process will get blocked, when I use it too late, I get overwhelmed by zombies and cannot fork() anymore, which is not only bad for my process, but can cause unexpected problems on the whole system.

I’ll probably have to program some logic of using some maximum number of children and block the parent when that number is reached – but that should be not necessary because most of the children terminate quickly. The other solution that I can think of (creating a two-tiered parent process that spawns concurrent children which in turn concurrently spawn and wait for grandchildren) is too complicated for me right now. Possibly I could also find a non-blocking function to check for the children and use waitpid only when they have terminated.

Nevertheless the question:

Why does Linux keep zombies at all? Why do I have to wait for my children? Is this to enforce discipline on parent processes? In decades of using Linux I have never got anything useful out of zombie processes, I don’t quite get the usefulness of zombies as a “feature”.

If the answer is that parent processes need to have a way to find out what happened to their children, then for god’s sake there is no reason to count zombies as normal processes and forbid the creation of non-zombie processes just because there are too many zombies. On the system I’m currently developing for I can only spawn 400 to 500 processes before everything grinds to halt (it’s a badly maintained CentOS system running on the cheapest VServer I could find – but still 400 zombies are less than a few kB of information)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T21:26:46+00:00Added an answer on May 27, 2026 at 9:26 pm

    I’ll probably have to add a process table that stores the child pids
    and have to use waitpid – not immideately, but after some time has
    passed – which is a problem, because the running time of the children
    varies from few microseconds to several minutes. If I use waitpid too
    early, my parent process will get blocked

    Check out the documentation for waitpid. You can tell waitpid to NOT block (i.e., return immediately if there are no children to reap) using the WNOHANG option. Moreover, you don’t need to give waitpid a PID. You can specify -1, and it will wait for any child. So calling waitpid as below fits your no-blocking constraint and no-saving-pids constraint:

    waitpid( -1, &status, WNOHANG );
    

    If you really don’t want to properly handle process creation, then you can give the reaping responsibility to init by forking twice, reaping the child, and giving the exec to the grandchild:

    pid_t temp_pid, child_pid;
    temp_pid = fork();
    if( temp_pid == 0 ){
        child_pid = fork();
        if( child_pid == 0 ){
            // exec()
            error( EXIT_FAILURE, errno, "failed to exec :(" );
        } else if( child_pid < 0 ){
            error( EXIT_FAILURE, errno, "failed to fork :(" );
        }
        exit( EXIT_SUCCESS );
    } else if( temp_pid < 0 ){
        error( EXIT_FAILURE, errno, "failed to fork :(" );
    } else {
        wait( temp_pid );
    }
    

    In the above code snippet, the child process forks its own child, immediately exists, and then is immediately reaped by the parent. The grandchild is orphaned, adopted by init, and will be reaped automatically.

    Why does Linux keep zombies at all? Why do I have to wait for my
    children? Is this to enforce discipline on parent processes? In
    decades of using Linux I have never got anything useful out of zombie
    processes, I don’t quite get the usefulness of zombies as a “feature”.
    If the answer is that parent processes need to have a way to find out
    what happened to their children, then for god’s sake there is no
    reason to count zombies as normal processes and forbid the creation of
    non-zombie processes just because there are too many zombies.

    How else do you propose one may efficiently retrieve the exit code of a process? The problem is that the mapping of PID <=> exit code (et al.) must be one to one. If the kernel released the PID of a process as soon as it exits, reaped or not, and then a new process inherits that same PID and exits, how would you handle storing two codes for one PID? How would an interested process retrieve the exit code for the first process? Don’t assume that no one cares about exit codes simply because you don’t. What you consider to be a nuisance/bug is widely considered useful and clean.

    On the system I’m currently developing for I can only spawn 400 to 500
    processes before everything grinds to halt (it’s a badly maintained
    CentOS system running on the cheapest VServer I could find – but still
    400 zombies are less than a few kB of information)

    Something about making a widely accepted kernel behavior a scapegoat for what are clearly frustrations over a badly-maintained/cheap system doesn’t seem right.

    Typically, your maximum number of processes is limited only by your memory. You can see your limit with:

    cat /proc/sys/kernel/threads-max
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Even though it's not part of HTTP 1.1/RFC2616 webapps that wish to force a
One of my co-workers claims that even though the execution path is cached, there
I saw that __VIEWSTATE field gets rendered even though I have set the EnableViewState=false
I've got a project that consists of two processes and I need to pass
Even though I always strive for complete validation these days, I often wonder if
Even though I have a robust and fast computer (Pentium Dual Core 2.0 with
Even though I've been a developer for awhile I've been lucky enough to have
Even though MDI is considered harmful , several applications (even MS Office, Adobe apps)
Even though it is possible to write generic code in C using void pointer(generic
Why is it necessary even though everything is specified in a makefile?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.