in reply to Objects and forking

I guess you only wrote it like this in this example, but just for reference, I've seen too many people ignoring errors. You should test the return value of the fork() better. It's a nonzero number in the parent, zero in the child and undef if the fork() failed!:

my $pid = fork(); die "Ouch, can't fork: $^En\" unless defined $pid; unless ($pid) { ... }
or if you want it to look more like your code:
unless (my $pid = fork()) { die "Ouch, can't fork: $^En\" unless defined $pid; ... }

Jenda
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
   -- Rick Osborne

Edit by castaway: Closed small tag in signature

Replies are listed 'Best First'.
Re: Re: Objects and forking
by gnu@perl (Pilgrim) on Jul 11, 2003 at 13:35 UTC
    Good point. The real code is much more involved than this tiny sample I threw in, but in the real thing I did forget to check and see if the fork even worked. Without checking if a fork failed, my program would seem to have run fine, no errors reported or anything.