Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^4: process synchronize.... Please help me out

by sandy1028 (Sexton)
on Apr 22, 2009 at 05:32 UTC ( [id://759186]=note: print w/replies, xml ) Need Help??


in reply to Re^3: process synchronize.... Please help me out
in thread process synchronize.... Please help me out

$#tmp count is 100.
foreach my $i (0..$#tmp) { # Forks and returns the pid for the child: my $pid = $pm->start($i); if ($pid) { print "Pid of Child process $pid\n"; next; }; }
Prints out the child process 100 times. The below code reads the files in directory and splits files and directory name.
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);
The below code calls the subroutine which opens the log file in append mode and write to file. here all the process write to the file and it is not synchronized. The problem is to write to log file one process after the another.
$process->($dir, $file, $config, $log); } $pm->finish; # Terminates the child process
How can I do this

Replies are listed 'Best First'.
Re^5: process synchronize.... Please help me out
by Corion (Patriarch) on Apr 22, 2009 at 07:00 UTC

    You've been shown many approaches and many solutions already. You can serialize the log writing by locking the log file handle. You can write to different log files. You can write to a central logging process.

    So far, I have not seen any try at using the code you've been given, only more questions on "how can I do this". I think you need to take a step back and identify how each solution will solve your problem and then choose the solution that you understand best.

      Can anyone provide me tutorial regarding how to serialize the processes and write to multiple log files....
      I tried using lock and waitpid() functions but no luck

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://759186]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (5)
As of 2024-04-16 13:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found