The UNIX and Linux Forums  

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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Code Understand ? varungupta UNIX for Advanced & Expert Users 2 05-02-2008 04:34 PM
execution status of gotoURL in Win32::IEAutomation gurukottur Shell Programming and Scripting 2 11-21-2007 11:27 PM
Capturing last command execution status in a script. videsh77 Shell Programming and Scripting 2 04-12-2007 10:19 AM
Process launched by user who logs out, continue running ? Browser_ice UNIX for Dummies Questions & Answers 2 08-08-2006 06:43 AM
Status code of last command execution tipsy Shell Programming and Scripting 1 07-21-2006 10:14 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-03-2008
sysgate's Avatar
Unix based
 

Join Date: Nov 2006
Location: /root
Posts: 1,160
Stumble this Post!
perl - understand process status and continue the code execution

Hello, I need advice on how to check if started processes are finished in perl, here's explanation :
OS is RHEL 4, perl -v = "This is perl, v5.8.0 built for i386-linux-thread-multi"

The logic of the script :
Code:
#!/usr/bin/perl

use warnings;
$param1 = $ARGV[0];
$param2 = $ARGV[1];
$param3 = $ARGV[2];

sub Help
{ help message goes here }
# some other subroutines follow

# main 
if (@ARGV < 3) {
        &Help; exit 1;
}
&cleanUp(); # pre-defined sub is being invoked here, stuff like $| = 1;
if ( $vars eq 'something' ) {
        &call_some_sub;
        } else {
        &call_another_sub;
}
Pretty simple, given that I'm not so good at perl, I wrote that for test.
So, what I'm basically doing is starting file transfers via ssh or other protocol with custom binary, and I need to check somehow that the transfers are done and then continue with other code executiom, in my case that will be another subroutine call, doing some static stuff. Quering the OS with "system ("pgrep pattern") every 1 second doesn't seem good, so I'm thinking of using fork() in order to trap the transfers' end. If that's the right way, I guess it should look like :
Code:
&start_transfers;
# somehow understand that they are done
&static_stuff_sub;
I've read the documentation for fork(); but I'm not sure if that's the right way. I guess my issue is that the file size vary from 10kb to 10Gb sometimes and I can't predict time to wait (using sleep for example). I'll appreciate any pointers.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 01-03-2008
Moderator
 

Join Date: Sep 2002
Location: Hong Kong, China
Posts: 1,428
Stumble this Post!
Try waitpid().

waitpid - perldoc.perl.org
Reply With Quote
  #3 (permalink)  
Old 01-04-2008
sysgate's Avatar
Unix based
 

Join Date: Nov 2006
Location: /root
Posts: 1,160
Stumble this Post!
Thanks cbkihong, I saw that already, this would probably require fork(); but it won't work for me, at least in the way I wanted, I have arbitrary number of processes started via system command, and I can't use their PIDs, plus the execution of the subroutine call itself is successful, so I cannot do even :
Code:
wait &sub-call;
    if ($? == 0) {
        # do something else;
}
I think I'll wait for STDIN interaction while "chomp"-ing the input, this should ensure that processes / SSH transfers in the background are done, assuming someone is looking at the external log file in real time.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 11:59 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0