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

  • Home
  • SEARCH
  • 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 8986449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:33:09+00:00 2026-06-15T21:33:09+00:00

My main process spawns a child process. If the main process is killed, the

  • 0

My main process spawns a child process. If the main process is killed, the child would be assigned ppid of 1. When the child exits, it would become a zombie as init has not called wait() on this child. Is there a way to avoid this situation?

  • 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-06-15T21:33:11+00:00Added an answer on June 15, 2026 at 9:33 pm

    init will call wait() on processes that it inherits. Zombies should only exist where the child has exited but the parent is still around, but is yet to reap the exit code. From the init manpage:

    init is the parent of all processes on the system, it is executed by the kernel and is responsible for starting all other processes; it is the parent of all processes whose natural parents have died and it is responsible for reaping those when they die.

    You should make a distinction between orphans (they’re still alive, their parent is dead and hence they’ve been adopted by init), and zombies (they’re dead but their parent is alive and has not yet reaped them).

    Orphans will become zombies for a very short period of time after they exit but before init reaps them but this period should be small enough that no-one notices. In fact, all exiting processes (except possibly init itself) go through this short zombie phase, it’s only those cases where the parent doesn’t reap quickly enough that you notice.


    The actual code in the init child death (SIGCHLD) handler goes something like this (my comments):

    void chld_handler (int sig) {
        CHILD  *ch;
        int    pid, st;
        int    saved_errno = errno;
    
        while ((pid = waitpid(-1, &st, WNOHANG)) != 0) { // << WAIT done here
            if (errno == ECHILD) break;
            for (ch = family; ch; ch = ch->next) {
                if (ch->pid == pid && (ch->flags & RUNNING)) {
                    INITDBG (L_VB, child_handler: marked %d as zombie", ch->pid);
                    ADDSET (got_signals, SIGCHLD);
                    ch->exstat = st;
                    ch->flags |= ZOMBIE;                 // Set to zombie here.
                    if (ch->new) {
                        ch->new->exstat = st;
                        ch->new->flags |= ZOMBIE;
                    }
                    break;
                }
            }
            if (ch == NULL) {
                INITDBG (L_VB, "chld_handler: unknown child %d exited.", pid);
            }
        }
        errno = saved_errno;
    }
    

    And then, later on in the main loop (not signal handler), any processes in the process table marked as ZOMBIE are cleaned up:

    if (ISMEMBER (got_signals, SIGCHLD)) {
        INITDBG(L_VB, "got SIGCHLD");
        /* First set flag to 0 */
        DELSET(got_signals, SIGCHLD);
    
        /* See which child this was */
        for (ch = family; ch; ch = ch->next) {
            if (ch->flags & ZOMBIE) {                    // ZOMBIE detected here
                INITDBG (L_VB, "Child died, PID= %d", ch->pid);
                ch->flags &= ~(RUNNING|ZOMBIE|WAITING);  // And cleared here.
                if (ch->process[0] != '+') {
                    write_utmp_wtmp ("", ch->id, ch->pid, DEAD_PROCESS, NULL);
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a main application that spawns a seperate thread to process messages off
I have a main process that spawns Processes and then those Processes add jobs
Have a Parent process which spawns multipe child process via fork. I want the
I use posix_spawnp to spawn child processes from my main process. int iRet =
Lets write simple console application (debug mode): static void Main(string[] args) { Process p
I want the parent process to take the arguments to main() and send the
Does the main function we define in C or C++ run in a process
Why won't XMLSerializer process my generic list? Sub Main() Serializing() End Sub <System.Serializable()> _
There are various ways of exiting a process: e.g.: ExitProcess, ExitThread (from the main
My application uses a Spring DefaultMessageListenerContainer to process incoming messages. The main method of

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.