in reply to controling the num of fork sessions
If you're asking how to keep 20 child processes active at any given time, keep track of them and use waitpid to see how many are gone:
But like I said, this makes no sense with respects to processes running on other systems. You may have to give us more information if this doesn't help you.use POSIX ':sys_wait_h'; my $max_children = 20; my $cur_children = 0; $SIG{CHLD} = sub { $cur_children-- while waitpid(-1, &WNOHANG) != -1; &spawn_children; } sub spawn_children { while ($cur_children < $max_children) { my $pid = fork; die "fork: $!" unless defined $pid; &child_process if !$pid; $cur_children++; } } sub child_process { # what the kid does exit 0; # important } &spawn_children;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: controling the num of fork sessions
by mikfire (Deacon) on Nov 27, 2000 at 19:51 UTC | |
by Fastolfe (Vicar) on Nov 27, 2000 at 21:13 UTC | |
|
Re: Re: controling the num of fork sessions
by Anonymous Monk on Nov 27, 2000 at 05:26 UTC |