Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

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

by Anonymous Monk
on Apr 22, 2009 at 04:39 UTC ( [id://759182]=note: print w/replies, xml ) Need Help??

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

How to lock the processes for writing in to the log file.
Now all the process does not synchronize and all the processes write to single log file and some of the logging information is missed.
How can I create a separate log file for each processes or synchronize all processes to write to single log file
  • Comment on Re^2: process synchronize.... Please help me out

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

    By writing code to use separate log files?

    I'm not sure where you have problems. You didn't post any code that shows the problem and it seems to me that you are simply continuing a series of fruitless posts of sandy1028 who seems to expect to get his/her code written by us. This is not how this site works. If you want to write a program that runs multiple instances of itself in parallel, you will have to learn how to program first. Generating multiple log file names is not hard.

      $#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

        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.

Log In?

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (2)
As of 2024-04-20 19:10 GMT
Find Nodes?
    Voting Booth?

    No recent polls found