dr.jekyllandme has asked for the wisdom of the Perl Monks concerning the following question:
The above code is wrong because every process sleeps for 2 mins and they resume at the same time. Instead I would like process 0 to start, 2 mins goes by, then process 1 joins, 2 mins go by and then process 3 joins, etc... Is there someway to do this? Thanks for your help.#!/usr/software/bin/perl5.8.8 -w use strict; use warnings; use Cwd qw(abs_path); use Parallel::ForkManager; my $pm = new Parallel::ForkManager(8); $pm->run_on_finish(sub { my($pid, $exit_code) = @_; my $output = "$pid has finished with exit code $exit_code.\n"; print $output; }); foreach my $x (0..2) { $pm->start($x) and next; sleep(1); # I want to sleep for 2 mins before the next process kic +ks off. my $time = time; print "$x\n"; print "$time\n"; $pm->finish(); } $pm->wait_all_children;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to sleep before the next fork kicks off?
by GrandFather (Saint) on Jan 17, 2014 at 02:21 UTC | |
by dr.jekyllandme (Sexton) on Jan 17, 2014 at 15:52 UTC | |
|
Re: How to sleep before the next fork kicks off?
by kcott (Archbishop) on Jan 17, 2014 at 02:25 UTC | |
|
Re: How to sleep before the next fork kicks off?
by zentara (Cardinal) on Jan 17, 2014 at 12:57 UTC |