:: Re: [DNG] Reaping orphan processes.
Top Page
Delete this message
Reply to this message
Author: aitor
Date:  
To: dng
Subject: Re: [DNG] Reaping orphan processes.
Hi Hendrik,

On 4/3/23 22:48, Hendrik Boom wrote:
> Perhaps, technically, that is what I asked for. But your example was still helpful. Often, as in this case, the answer has to go beyond the question for full understanding.


Removing the neverending while(1) loop in the parent of the above example, you'll get an example
of an orphan process reclaimed by init. Indeed, if you run the `pstree` command before such time
has expired, you'll see the child process reparented to PID1.

In summary:

  - Zombie processes are when the parent is alive and child is dead, but the parent
    doesn't call waitpid()


  - Orphan processes are when parent had returned when child is alive, and they
    belong to init.


It's worth to clarify that the "double fork() + setsid()" -widely used in daemons running in the
background in order to prevent the child from ever acquiring a controlling terminal and become
a session leader-, will lead to a fully detached process that is reclaimed by init as well. The
grandparent never waits on children; children without a parent are reparented to init.

Cheers,

Aitor.