sandy1028 has asked for the wisdom of the Perl Monks concerning the following question:
my $log = IO::File->new(">$log_file_name"); $log->print("date()."--\n\n\n"); sub process { my ($sub_dir, $file, $config, $log) = @_; $log->print("-- Reading $file file\n"); }
Here 5 process is created and subroutine is called from another file which opens a log file write.my $pm = new Parallel::ForkManager($tc+1); $pm->run_on_finish( sub { my ($pid, $exit_code, $ident) = @_; $tmp +Files[$ident] = undef; } ); foreach my $i (0..$#tmp) { # Forks and returns the pid for the child: my $pid = $pm->start($i) and next; $SIG{INT} = 'DEFAULT'; my $filename = $tmp[$i]->filename(); my $file = IO::File->new("<$filename") or die "Can't open $filen +ame\n"; while((my $line) = $file->getline()) { last unless defined($line); chomp $line; my ($dir, $file) = split(/\t/, $line); # my $process = shift; is created above # Calling this from another file $process->($dir, $file, $config, $log); } $pm->finish; # Terminates the child process }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: process synchronize.... Please help me out
by Corion (Patriarch) on Apr 21, 2009 at 12:04 UTC | |
by Anonymous Monk on Apr 22, 2009 at 04:39 UTC | |
by Corion (Patriarch) on Apr 22, 2009 at 05:15 UTC | |
by sandy1028 (Sexton) on Apr 22, 2009 at 05:32 UTC | |
by Corion (Patriarch) on Apr 22, 2009 at 07:00 UTC | |
|