[prev in list] [next in list] [prev in thread] [next in thread] 

List:       hpux-devtools
Subject:    RE: HPUX-DEVTOOLS: The Zombie Process
From:       "Harrison, Bruce (CXO)" <Bruce.Harrison () COMPAQ ! com>
Date:       2001-07-16 16:32:47
[Download RAW message or body]


I have code that needed to periodically take care of its zombies, so I wrote
the following function that the parent calls periodically in its main loop.

#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <wait.h>

int wait_for_children(int num_to_wait_for, int timeout, int verbose)
 {

// This function will wait for the specified number of children to
terminate.  It 
// will wait only the number of seconds indicated in the timeout value
specifed.
   //
// This function returns the actual number of child processes that
terminated.
int child_status, term_child_counter;
pid_t child_pid;
term_child_counter = 0;
while (1)
   {
while ((child_pid = waitpid((pid_t)-1,&child_status,WNOHANG)))
     {
if (child_pid == (pid_t) -1)
       {
        /*
The waitpid function returned an error.  If the error is ECHILD (no more
child processes), that O.K.
        */
if (errno != ECHILD)
fprintf(stderr,"Error returned from waitpid! Error is %d\n",errno); break;
       }
else
       {
term_child_counter++;
if (verbose)
printf("Child process with pid of %d terminated!  Terminated child counter
is now %d\n",
child_pid,term_child_counter);
       }

}  /* End of the while we have (terminated) children loop */
if ( (timeout-- > 0) && (num_to_wait_for != term_child_counter) )
sleep(1);
else
break;
}  /* End of the while (1) loop */
return(term_child_counter);
}  /* End of the wait_for_children function */


 -----Original Message-----
From: 	BENNETT,ANDY (HP-Unitedkingdom,ex1) [mailto:andy_bennett@hp.com] 
Sent:	Monday, July 16, 2001 3:29 AM
To:	'hpux-devtools@cxx.cup.hp.com'
Subject:	RE: HPUX-DEVTOOLS: The Zombie Process

I don't think it is possible to achieve this without changing the parent's
code. A zombie process is one that has exit()ed and has been stripped of all
of its resources. All that is left is a process table entry containing its
exit status that it wants to give to its parent. The only way to get rid of
them is to have something wait() for them, see "man 2 wait" for details of
this. It is the parent that is responsible.

It is possible to get rid of them by killing the parent so they get
reparented to something that will wait() for them, but you probably don't
want to do this.

Regards,
Andy.



> -----Original Message-----
> From: CAO,THOMAS-DS (HP-China,ex2) [mailto:thomas-ds_cao@hp.com]
> Sent: 16 July 2001 09:55
> To: 'hpux-devtools@cxx.cup.hp.com'
> Subject: HPUX-DEVTOOLS: The Zombie Process
> 
> 
> Hi all,
> How to get rid of the zombie process without changing the 
> code of either the
> child process nor the parent.
> 
> Thanks in advance
> 
> Best regards,
> Thomas Cao
>  _________________________________________________________________
>  To leave this mailing list, send mail to majordomo@cxx.cup.hp.com
>     with the message UNSUBSCRIBE hpux-devtools
>  _________________________________________________________________
> 
 _________________________________________________________________
 To leave this mailing list, send mail to majordomo@cxx.cup.hp.com
    with the message UNSUBSCRIBE hpux-devtools
 _________________________________________________________________
 _________________________________________________________________
 To leave this mailing list, send mail to majordomo@cxx.cup.hp.com
    with the message UNSUBSCRIBE hpux-devtools
 _________________________________________________________________

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic