in reply to Fork parent process dies unexpectedly
The problem is probably the PIPE signal. On UNIX platforms, when you write to a file descriptor that is no longer writable (because the receiving end closed it), you get a SIGPIPE delivered to your program.
This signal is there to inform you that you can no longer write to that file descriptor, and it's default behavior is to kill your program (no point in e.g. cat file | wc -l continuing to write to the pipe after wc has already died).
In client/server applications this default behavior is no longer appropriate, because the server persists.
BTW, there are many fantastic modules for writing daemons on the CPAN... Others have already posted them. Have a look!
Update: oh... i forgot how to get around SIGPIPE:
or$SIG{PIPE} = sub { warn "client closed" };
$SIG{PIPE} = 'IGNORE';
|
---|