Brad Fitzpatrick (brad) wrote,
Brad Fitzpatrick

wait(2)-equivalent in an event loop?

Say I have a parent process and a bunch of child processes, and I want an event loop in the parent.

Is there a way to get a filehandle in the parent which becomes readable once a child has died? I can then put that filehandle in my event loop. I don't want to poll waitpid(0, NULL, WNOHANG) every 'n' seconds. That's a lame tradeoff between latency and sucking CPU.

Yeah, I can catch SIGCHLD, but I'd prefer to avoid that.

Some google queries:

Python's Twisted framework catches SIGCHLD, sets a flag, and then reaps children as part of its event loop? (Python's signal handling is like Perl's pre-5.8... unsafe, possibly between opcodes)

Pert's POE seems to block SIGCHLD at times and poll for dead children at other times:

OCaml does more polling/SIGCHLD stuff:

So I'm starting to think there is no clean way, at least for what I consider clean. It's also entirely possible I have no clue what I'm talking about.

I could just have each child connect to a server in the parent, and when that connection dies, I know the child is gone?

Tags: perl, tech
  • Post a new comment


    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.