rhymejerky has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I have written a concurrent server that listen for connection. Once it accepts a connection, the server fork a child and it handles the communication. The parent goes back to listen for another connection. Everything works fine, until the child process exit (I do an exit(0) when the child sends the last piece of info back). The child doesn't exit cleanly and I end up with a bucnh of <defunct> process. Did a google and ppl suggested to use waitpid on the parent which defeats the idea of having a concurrent server. Can anyone shed some light on this? Thanks a bucnh!!

Replies are listed 'Best First'.
Re: concurrent server
by moot (Chaplain) on Mar 16, 2005 at 00:17 UTC
    Have you actually read the documentation of waitpid? If so, you'll know that you can do a non-blocking wait for any child processes, and if none have exited continue to process the rest of your app.
      Ah, thank you for pointing out waitpid can be noblocking. I must have missed the WNOHANG portion when I looked at the man page. I ended up doing $SIG{CHLD} = 'IGNORE'; because I don't really care the exit code of my child.
Re: concurrent server
by t-rex (Scribe) on Jun 20, 2016 at 06:05 UTC

    could you share the code of concurrent server you implemented? I am looking for something like that, i will have an example to refer to. Thanks

      Unlikely. rhymejerky was here last in 2011.

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)