Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Thank you.use strict; # use this array to simulate 10 tasks my @array = qw(zero one two three four five six seven eight nine ten); my $count=0; my $num_of_tasks = 5; for (1..$num_of_tasks) { my $pid = fork(); if ($pid) { $count++; waitpid($pid,0); } elsif ($pid == 0) { test(); } else { die "couldn’t fork: $!\n"; } } print "Done\n\n"; sub test { # do the work here print "text=$array[$count]\n"; sleep 1; exit(0); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Trouble getting started with fork
by almut (Canon) on Mar 03, 2010 at 21:08 UTC | |
by ikegami (Patriarch) on Mar 03, 2010 at 21:12 UTC | |
by sierpinski (Chaplain) on Mar 04, 2010 at 17:17 UTC | |
|
Re: Trouble getting started with fork
by ikegami (Patriarch) on Mar 03, 2010 at 21:10 UTC | |
|
Re: Trouble getting started with fork
by pajout (Curate) on Mar 04, 2010 at 19:30 UTC |