Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 7 Nov 1997 21:47:08 -0500
From:      Jim Carroll <jim@carroll.com>
To:        freebsd-questions@freebsd.org
Subject:   wait not interrupted on signal
Message-ID:  <Pine.BSD.3.91.971107213028.20097L-100000@apollo.carroll.com>

next in thread | raw e-mail | index | archive | help

 I have a piece of code that depends on being notified when a child  process
 sends  it  a  signal.  The parent spends most of it's life waiting for this
 signal.

 The  mechanism  I  have tried to use is to trap SIGUSR1 in the parent, then
 execute a wait() system call. From my reading of the wait(2) man pages  and
 the  sigaction(2)  pages, the wait call in the parent should be interrupted
 when the child task posts SIGUSR1.
 
 I'm  not  sure  what  I'm  doing wrong, but I cannot get the wait() call to
 interrupt. I had print routines that seem to indicate that the  signal  was
 caught, but the wait refuses to return to the parent until the child dies.
 
 I have narrowed the problem down to the smallest  piece  of  code  I  could
 develope,  and  included  it below. In the example below, I would expect to
 see:

 wait for child
 SIGUSR1 caught
 errno: 4 
 
 The last line indicates that an errno 4 (EINTR) was received.
 
 Instead, we are seeing:
 
 wait for child
 SIGUSR1 caught
 errno: 0

 We are running FreeBSD 2.2.1

 Any assistance would be appreciated.
 
 Thanks in advance
 
=-=-=-=-= SAMPLE CODE -=-=-=-=-=-=-=
 
#include <sys/errno.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/wait.h>

void sigreset(int s) {
    fprintf(stderr,"SIGUSR1 caught\n");
    }

void main(int argc, char* argv[]) {

    int p, s;


    signal(SIGUSR1, sigreset);          /* prepare to catch signal */

    if ((p = fork()) == 0) {            /* in child */

        sleep(2);
        kill(getppid(), SIGUSR1);       /* post signal to parent */
        sleep(5);
        return;
        }

                                        /* in parent */
    fprintf(stderr, "wait for child\n");

    wait(&s);                           /* wait for EINTR or child dealth */

    fprintf(stderr, "errno: %d\n", errno);
    }


---
Jim C., President       | C A R R O L L - N E T, Inc.
201-488-1332            | New Jersey's Premier Internet Service Provider
www.carroll.com         | 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSD.3.91.971107213028.20097L-100000>