This is the mail archive of the cygwin@sources.redhat.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: 1.1.4, select, and SIGCHLD


> From: uunet!sources.redhat.com!cygwin-owner
> [mailto:uunet!sources.redhat.com!cygwin-owner]On Behalf Of
Christopher
> Faylor
> Sent: Wednesday, November 01, 2000 1:46 PM
> To: uunet!sources.redhat.com!cygwin
> Subject: Re: 1.1.4, select, and SIGCHLD
> 
> 
> On Wed, Nov 01, 2000 at 08:52:36AM -0800, Robert Fidler wrote:
> >I am seeing behavior where a daemon process has multiple children
die
> >'simultaneously' and subsequent calls to select() consistently
return
> >-1 immediately with errno set to EINTR.  This puts the daemon into a
> >tight spinloop and it becomes useless.  If the child deaths are
> >sequential, the daemon behaves properly.
> >
> >I've seen this behavior on cygwin 1.1.4 and 1.1.5-2.  Has anyone
else
> >seen this behavior and is there a fix for it?
> 
> No, and no.
> 
> cgf
> 

Below is a test program that exhibits the behavior I described.  By
defining WORKS, you will add a 1 second sleep between the kills and
the program will work as expected.
Robert

#include <stdio.h>
#include <errno.h>
#include <signal.h>
#include <sys/wait.h>

#define NCHILDREN   10

void die(int sig) {
    printf("child exiting\n");
    exit(0);
}

void reaper(int sig) {
    int pid, status;

    printf("reaping processes...\n");
    while ((pid = waitpid(-1, &status, WNOHANG)) > 0) {
        printf("reaping process %d that exited with status %d\n",
status);
    }
}

int main(int argc, char **argv) {

    int i;
    int childpid[NCHILDREN];
    struct sigaction saction;

    saction.sa_handler=die;
    saction.sa_mask=0;
    saction.sa_flags=0;
    sigaction(SIGTERM, &saction, NULL);

    /*
     * Fork off children that do nothing but sleep.
     */
    for (i=0; i<NCHILDREN; i++) {
        if ((childpid[i] = fork()) == 0) {  /* child */
            sleep(10000);
        }
    }

    saction.sa_handler=reaper;
    sigaction(SIGCHLD, &saction, NULL);

    for (i=0; i<NCHILDREN; i++) {
        kill(childpid[i], SIGTERM);
#ifdef WORKS
        sleep(1);
#endif
    }

    while (1) {
        /* wait forever */
        printf("heading into the select\n");
        if (select(0, NULL, NULL, NULL, NULL) < 0) {
            if (errno == EINTR) {
                printf("select was interrupted, continuing\n");
                continue;
            }
        }
        /* do some stuff */
    }
}

__________________________________________________
Do You Yahoo!?
From homework help to love advice, Yahoo! Experts has your answer.
http://experts.yahoo.com/

--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]