Occasional Zombie

Occasional Zombie

Post by Alan Cliffor » Thu, 10 Jan 2002 07:12:50



I am doing something wrong.   I have:

 sa.sa_handler = sigchld_handler;
 sigemptyset(&sa.sa_mask);
 sa.sa_flags = SA_RESTART || SA_NOMASK;
 if (sigaction(SIGCHLD, &sa, NULL) == -1) {
        int errornumber = errno;
        syslog(LOG_USER | LOG_INFO, "Signal handler error: %s",
           strerror(errornumber));
        // perror("sigaction");
        // exit(1);
 }

void sigchld_handler(int s) {
    /* zombie handler */
    pid_t pid;
    pid = waitpid(-1, &Child_pid_status, WNOHANG);
    if (pid == Child_pid) {
        // printf("zombie handler: connector child %d died\n", pid);
        Child_pid = getpid();  /* for testing - a child can't be this */
        set_all_clients_unconnected();
        set_message(NULL); // clear the message buffer
        /* flag as not connected */
        Child_status_flags &= ~1;
        /* if the child has died, we need to kill the info child */
        /* ensure that the child pid has been reset to getpid() first */
        set_online_flag(0);
    }
    else if (pid == Info_oneshot_pid) {
        // printf("zombie handler: info oneshot child %d died\n", pid);
        Info_oneshot_pid = getpid();  /* for testing - a child can't be
           this */
    }

Quote:}

Two children, the one with Child_pid is running, the Info_oneshot is run
every 15 seconds, does a quick job and exits.  Very infrequently, I am
left with a zombie for the Child_pid process.

A user action can cause both children to be killed at the same time (in
human timescale).  Or the Info_oneshot process could selfdestruct at the
same time as the Child process is killed.  Is it possible for two signals
to be received at the same time and one ignored?

Any advice on a handler for two children would be gratefully received.

Alan

(If replying by mail, change scatology to AC2)

 
 
 

Occasional Zombie

Post by Chuck Dillo » Thu, 10 Jan 2002 07:28:36



> void sigchld_handler(int s) {
>     /* zombie handler */
>     pid_t pid;

do {

Quote:>     pid = waitpid(-1, &Child_pid_status, WNOHANG);
>     if (pid == Child_pid) {
>         // printf("zombie handler: connector child %d died\n", pid);
>         Child_pid = getpid();  /* for testing - a child can't be this */
>         set_all_clients_unconnected();
>         set_message(NULL); // clear the message buffer
>         /* flag as not connected */
>         Child_status_flags &= ~1;
>         /* if the child has died, we need to kill the info child */
>         /* ensure that the child pid has been reset to getpid() first */
>         set_online_flag(0);
>     }
>     else if (pid == Info_oneshot_pid) {
>         // printf("zombie handler: info oneshot child %d died\n", pid);
>         Info_oneshot_pid = getpid();  /* for testing - a child can't be
>            this */
>     }
} while (waitpid continues to reap kids);
> }
> Is it possible for two signals
> to be received at the same time and one ignored?

Sort of.  The bottom line is that you can't assume that your handler will fire
once per child.

-- ced

--
Chuck Dillon
Senior Software Engineer
Accelrys Inc., a subsidiary of Pharmacopeia, Inc.

 
 
 

Occasional Zombie

Post by Alan Cliffor » Thu, 10 Jan 2002 12:10:23


CD>
CD> > Is it possible for two signals
CD> > to be received at the same time and one ignored?
CD>
CD> Sort of.  The bottom line is that you can't assume that your
CD> handler will fire once per child.
CD>

Thanks.  That seems to be a rather vital piece of information.

(If replying by mail, change scatology to AC2)

 
 
 

1. zombies nothing than zombies on a SUN


I forgot to mention that I can not use the normal wait(0) method in a
signal handler which is activated on the signal of the child because in
this case the parent process which waits in in the accept routine will be
interrupted and can not wait anymore for sockets to connect.

You see my problem is not simple at all.

Roland

2. Probs with com ports

3. occasional restart of firewall needed, pls help

4. can't kill job in 7.0

5. Occasional hangs with vid mode switch

6. Difficulties with directories and paths with ProxyPass

7. Semi-occasional FreeBSD mini-FAQ

8. Help with setting up route

9. Help! httpd suffers occasional slowdowns

10. occasional problems with my NCSA httpd server: please help!

11. Occasional error when mounting NFS.

12. occasional panics with Solaris-2.6 and sendmail-8.9

13. Occasional dhcp problems on startup