Hi,
This code is based on creating the forking process. The problem is some of the files are written to the log file while reading a directory.
How can I change to multi-threading and write the read files to a log file using locking concept using thread.
or How can I use any kind of IPC for logging from all the spawned process which sends the back the message to main process for logging
Please help me..
Thanks in advanceCode:my $pm = new Parallel::ForkManager($tc+1); $pm->run_on_finish( sub { my ($pid, $exit_code, $ident) = @_; $tmp[$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 $filename\n"; while((my $line) = $file->getline()) { last unless defined($line); my ($dir, $file) = split(/\t/, $line); $proces->($dir,$file,$log); } $pm->finish; # Terminates the child process } $pm->wait_all_children; } return; }




Bookmarks