On Nov 12,  8:29am, [email protected] (David Holmes - Sun Microsystems) 
wrote:
-- Subject: Re: Anyway in java to way for the child process to wait for paren

| Paulo Levi said the following on 11/12/09 05:31:
| > In process builder.
| 
| No.
| 
| I'm not aware of any OS support for waiting for a parent process to die.
| 
| David Holmes

All the BSD's have it.

christos

#include <sys/types.h>
#include <sys/event.h>
#include <sys/time.h>
#include <stdio.h>
#include <unistd.h>
#include <err.h>

int
main(int argc, char *argv[])
{
        int kq, nev;
        struct kevent ev, ch;

        if ((kq = kqueue()) == -1)
                err(1, "Cannot create kqueue");

        EV_SET(&ch, getppid(), EVFILT_PROC, EV_ADD | EV_ENABLE | EV_CLEAR, 
            NOTE_EXIT, 0, 0);
        nev = kevent(kq, &ch, 1, &ev, 1, NULL);
        if (nev == -1)
                err(1, "kevent");
        if (nev == 0)
                errx("no event");
        if (ev.fflags & NOTE_EXIT)
                printf("my parent is now %u\n", (unsigned)getppid());
        else
                errx("unknown flags %x", ev.fflags);
        return;
}

Reply via email to