Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

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

by Corion (Patriarch)
on Apr 21, 2009 at 12:04 UTC ( [id://758948]=note: print w/replies, xml ) Need Help??


in reply to process synchronize.... Please help me out

Where do you print $pid? You declare two variables $pid in two places:

$pm->run_on_finish( sub { my ($pid, $exit_code, $ident) = @_; $tmpFile +s[$ident] = undef; } );

Here, $pid is likely the PID of the child that just terminated.

my $pid = $pm->start($i) and next;

Here, $pid will always be 0 after the next statement. Maybe you want something like this:

my $pid = $pm->start($i); if ($pid) { print "Launched child $pid\n"; next; };

Replies are listed 'Best First'.
Re^2: process synchronize.... Please help me out
by Anonymous Monk on Apr 22, 2009 at 04:39 UTC
    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

      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

Log In?
Username:
Password:

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

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

    No recent polls found