:: Re: [DNG] Reaping orphan processes.
Αρχική Σελίδα
Delete this message
Reply to this message
Συντάκτης: Hendrik Boom
Ημερομηνία:  
Προς: dng
Αντικείμενο: Re: [DNG] Reaping orphan processes.
On Sat, Mar 04, 2023 at 10:40:00PM +0100, aitor wrote:
> Hi again,
>
> On 4/3/23 22:30, aitor wrote:
> >
> > Hi Hendrik,
> >
> > On 4/3/23 18:44, Hendrik Boom wrote:
> > > Why can't they just terminate by themselves?
> > Consider the following example:
> >
> > /* ---------- example.c ------------ */
> > #include <stdio.h>
> > #include <stdlib.h>
> > #include <unistd.h>
> >
> > int main()
> > {
> >     int pid;
> >
> >     pid=fork();
> >     if(pid==0)
> >     {
> >         printf("\nI am the child\n");
> >         sleep(60);
> >         return 0;
> >     }
> >     if(pid>0)
> >     {
> >         while(1)
> >             printf("\nI am the parent\n");
> >     }
> >     return 0;
> > }
> >
> > /* ---------------------- */
> > Compile with `gcc example.c -o example` and run it.
> > Now get the pid of both the parent and the child. Say:
> > $ pidof example
> > 30260  30259
> > During the first 60 seconds you'll find the following line in "/proc/30260/status":
> >     State:    Z (sleeping)
> > that will be turned into:
> >     State:    Z (zombie)
> > at the end of the delay period. In this example, the child became a zombie process
> > because it exited but its parent is still alive and has not called wait() on it.
> > In this scenario, if you run the `ps` command you'll still find both processes; that is,
> > the original process (which is the parent spawned by the shell) and its child:
> > $ ps -A | grep example
> > 30259 pts/1    00:00:36 example
> > 30260 pts/1    00:00:00 example <defunct>
> > However, you'll not be able to terminate the zombie process by sending a signal to it.
> > HTH,
> > Aitor.

>
> Sorry, this is an example of a zombie process, created because the parent process didn't use the
> wait() system call to read its exit status of the child, but you are asking about orphan processes
> reclaimed by init when the parent terminates before the child.


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.

-- hendrik