Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

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

by Corion (Patriarch)
on Apr 22, 2009 at 05:15 UTC ( [id://759184]=note: print w/replies, xml ) Need Help??


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

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.

  • Comment on Re^3: process synchronize.... Please help me out

Replies are listed 'Best First'.
Re^4: process synchronize.... Please help me out
by sandy1028 (Sexton) on Apr 22, 2009 at 05:32 UTC
    $#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.

        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://759184]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2024-04-21 14:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found