The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Forking in Unix using C++ kkk02 High Level Programming 3 11-28-2008 09:53 AM
forking process. kymthasneem High Level Programming 2 06-23-2007 01:00 PM
forking a new process themezzaman High Level Programming 4 06-20-2006 04:13 AM
Forking manjuWicky UNIX for Advanced & Expert Users 3 10-07-2005 03:01 PM
Forking in a loop manjuWicky High Level Programming 1 10-07-2005 12:25 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-21-2009
sandy1028 sandy1028 is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 4
Problem with forking

Hi,


Code:
my $log = IO::File->new(">$log_file_name");
$log->print("date()."--\n\n\n");
sub process {
  my ($sub_dir, $file, $config, $log) = @_;
  $log->print("-- Reading $file file\n");
}
Code:
 my $pm = new Parallel::ForkManager($tc+1);
    $pm->run_on_finish( sub { my ($pid, $exit_code, $ident) = @_; $tmpFiles[$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);
        chomp $line;
        my ($dir, $file) = split(/\t/, $line);
        #  my $process = shift; is created above 
# Calling this from another file
        $process->($dir, $file, $config, $log);
      }
      $pm->finish; # Terminates the child process
    }
Here 5 process is created and subroutine is called from another file which opens a log file write. <br>
$process->($dir, $file, $config, $log);
The problem is while writing to the file some of the data is missed out because it is not synchronized.

How can I synchronize all the forked process to write to same log file or create a different log file for each.
or How can I create a threading process as the replacement for forking process

Thanks in advance.
  #2 (permalink)  
Old 04-22-2009
sandy1028 sandy1028 is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 4
Please help me with this..
How can I synchronize process to write to single log file or
How to create a separate log file for each process.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:31 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0