On Tue, 15 Oct 2002 08:01:43 +0200, [EMAIL PROTECTED] (Octavian Rasnita)
wrote:

>Can I run more processes in background?
>A process runs fine but I want to run more processes.

Maybe the Parallel::ForkManager module?

If you want to do it manually, here is a sub which will fork
a bunch of children and hand different data to each of them.
##############################################################
#!/usr/bin/perl
#For afork, the first argument is an array - a child will be
#forked for each array element. The second argument indicates the
maximum
#number of children that may be alive at one time. The third argument is
a
#code reference; this is the code that will be executed by the child.
One
#argument will be given to this code fragment. For afork, the array
element is
#passed. Note that this code will assume no other children will be
spawned,
#and that $SIG {CHLD} hasn't been set to IGNORE.
#by Abigail

if ($#ARGV < 0){@ARGV = qw( 1 2 3 4 5)}

afork (\@ARGV,10,\&hello);
print "Main says: All done now\n";

sub hello{
my $data = $_[0];
print "hello world from $data\n";}

##################################################
sub afork (\@$&) {
my ($data, $max, $code) = @_;
my $c = 0;
foreach my $data (@$data) {
wait unless ++ $c <= $max;
die "Fork failed: $!\n" unless defined (my $pid = fork);
exit $code -> ($data) unless $pid;
}
1 until -1 == wait;
}
#####################################################
#######################################################


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to