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



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-21-2006
Registered User
 

Join Date: Apr 2004
Posts: 2
Problem with storage of PID's to variables

I have the following problem to be solved:
I read a .csv file (tempfile), fetch the values into variables F1 to F5.
Variables F1, F2, F3 are parameters used for running a program (blablaprogram).
Variable F4 I want to use to store the PID-value in and variable F5 is used for storing the return value of the wait-process.
I want to distinquish the several parallel processes and monitor if they are finished. Problem is that I cannot store the PID into variables and read the content of the variable. At the line : echo "\n\t`date`:\t$F4 ........ , $F4 contains the variablename that has been read from the flatfile i.o. the PID.
Has anyone a suggestion?

The code (KSH) is shown underneath:

IFS=","
while read F1 F2 F3 F4 F5
do
blablaprogram $F1 $F2 > $LOGDIR/bes006_$F3.log 2>&1 &
set $F4=$!
echo "\n\t`date`:\t$F4 is Process ID for job waiting on $F1$F2"
wait $F4 # Wait until background process $F4 completes ...
set $F5=$?
echo "\n\tPID $F4: blabla Return Value for $F1$F2 concatination is: $F5"
case $F5 in
0) echo "\n\tConcatination on $F1$F2 COMPLETED Successfully"
;;
1) echo "\n\t!!! WARNING: Likely DATA ERROR ... !!!"
;;
2) echo "\n\t!!! FATAL ERROR ... !!!"
ERRORS=10; exit $ERRORS
;;
esac
echo "\n\t*********************************************************************"
done < $TEMPFILE
IFS=" "
Sponsored Links
  #2 (permalink)  
Old 11-21-2006
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,150
A process can only wait for its children. You can't wait for some random pid. You can loop until the process is no longer running. But then you will not be able to get the exit code. Maybe the process in question could be run by a wrapper which waits for it, obtains the exit code, and write it to a file or something.
  #3 (permalink)  
Old 11-22-2006
Registered User
 

Join Date: Apr 2004
Posts: 2
Thanks for quick feedback!
For the time being I've decided to process the jobs sequentially i.o. parallel. By creating an array I can store the PID's to this array and use it for the waiting step.
  #4 (permalink)  
Old 11-22-2006
grial's Avatar
grial grial is offline Forum Advisor  
El UNIX es como un toro
 

Join Date: Jun 2006
Location: Madrid (Spain)
Posts: 531
Quote:
Originally Posted by Perderabo
A process can only wait for its children. You can't wait for some random pid. You can loop until the process is no longer running. But then you will not be able to get the exit code. Maybe the process in question could be run by a wrapper which waits for it, obtains the exit code, and write it to a file or something.
That's right.
But what, from my point of view, is a little bit confusing is the "set $F4=$!". I mean, why "set $F4"? I would use simply "F4=$!"...
Continuing with what Perderabo said, perhaps this could help you

Code:
#!/bin/bash

for i in 1 2 3 4 5 6 7 8 9; do
   (
   sleep 10 &
   wait $!
   echo "sleep $i output was: $?"
   ) &
done

Tested in bash.

Regards.
Sponsored Links
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 Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Sun storage L7 Problem hadibn Solaris 0 04-03-2008 02:04 AM
Storage Solutions: Oracle and Symantec Certify Veritas Data - Data Storage Connection Linux Bot UNIX and Linux RSS News 0 07-20-2007 01:40 AM
killing PID's of ptree abhijeetkul Shell Programming and Scripting 0 06-20-2006 08:16 AM
Find PID's vibhor_agarwali UNIX for Advanced & Expert Users 2 08-16-2005 06:26 AM
Some problem about usb mass storage device niukun Linux 2 12-08-2004 01:05 PM



All times are GMT -4. The time now is 03:44 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-2010. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0