On Thu, 15 Dec 2005, Américo Albuquerque wrote:
> the spawn method does the fork. if it can't it return 0 and the server
> shutsdown. After about 20 successeful forks, I get "Resource temporarily
> unavailable" error. I've tried waitpid but it didn't work, after several
> forks I still get the same error
>
> this is the fork bit:
> my $kidpid = fork();
> unless(defined($kidpid)) {
> print "-ERR Can't fork: $!\n" if $self->verbose(2);
> $self->log("-ERR Can't fork: $!");
> print $sock "-ERR Can't fork: $!$self->{EOL}";
> my $child;
> while (($child = waitpid(-1,WNOHANG)) > 0) {
> print "Reaping $child\n" if $self->verbose(2);
> }
> return undef;
> }
>
> Am I doing the waitpid in the correct place?
No, you only collect child processes when fork() has already
failed. I would put the waitpid() loop in front of the call
to fork() to minimize the risk of fork() failing.
You'll still have an upper limit on the number of concurrent
pseudo-processes, but it should be closer to 60 than to 20.
However, you may want to look at memory consumption too,
as cloned Perl interpreters can take up a lot of memory.
Cheers,
-Jan
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs