in reply to Multi threaded server [fork]

This seems like strange behavior to me. I think what you need to do is call waitpid($child, 0); This should cause the parent process to continue to work. I think this would have been better done with threads, however, but that's just my opinion.

Here's an example of forking that I found on the net:

#!/usr/bin/perl use strict; use warnings; use POSIX ':sys_wait_h'; if (fork) { # parent print "[Parent]\n"; until (waitpid(-1, &WNOHANG)) { print "waiting...\n"; sleep 1; } print "[Parent End]\n"; } else { # child print "[Child]\n"; sleep 10; my $i = 1; print "[Child End]\n"; }
I think you're definitely going to need to use the signals.

Replies are listed 'Best First'.
Re: Re: Multi threaded server [fork]
by Deda (Novice) on Aug 07, 2003 at 08:04 UTC
    This variant would pause the parent process until the child finished its work, which is just the thing I am trying to avoid here (PS: parent always worked OK, problems arose when many clients connected - they only interfiered with each other, not with the parent). Anyway, I guess i'll have to do some reading about real threads and see what are the differences betewen threads and child processes.