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 and shell scripting languages 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 08:34 PM
execution status of gotoURL in Win32::IEAutomation gurukottur Shell Programming and Scripting 2 11-22-2007 03:27 AM
Capturing last command execution status in a script. videsh77 Shell Programming and Scripting 2 04-12-2007 02:19 PM
Process launched by user who logs out, continue running ? Browser_ice UNIX for Dummies Questions & Answers 2 08-08-2006 10:43 AM
Status code of last command execution tipsy Shell Programming and Scripting 1 07-21-2006 02:14 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-03-2008
sysgate's Avatar
sysgate sysgate is offline Forum Advisor  
Unix based
  
 

Join Date: Nov 2006
Location: Bulgaria
Posts: 1,323
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.
  #2 (permalink)  
Old 01-03-2008
cbkihong cbkihong is offline Forum Advisor  
Advisor
  
 

Join Date: Sep 2002
Location: Hong Kong, China
Posts: 1,624
Try waitpid().

waitpid - perldoc.perl.org
  #3 (permalink)  
Old 01-04-2008
sysgate's Avatar
sysgate sysgate is offline Forum Advisor  
Unix based
  
 

Join Date: Nov 2006
Location: Bulgaria
Posts: 1,323
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.
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 11:29 AM.


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