Problem with storage of PID's to variables


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem with storage of PID's to variables
# 1  
Old 11-21-2006
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=" "
# 2  
Old 11-21-2006
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  
Old 11-22-2006
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  
Old 11-22-2006
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 Smilie
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Problem to recognize a storage A5100

People i have solaris 9 in a sparc platform i`m tryng to conect a stora edge a5100.When i do a format i don't see the disk, later i do a touch /reconfigure reboot and nothing cant anybody help me? thank you (4 Replies)
Discussion started by: enkei17
4 Replies

2. AIX

Having problem with executing shell script to get the pid details!

Hello Everyone, I am new to shell scripting and also i am very new to AIX machine I have a question. I have shell script which contains the follwing "ps -e |grep $1 echo $2" i run this schell script by doing this ./startSehllscript 3444 passed with two parameters . Accroiding my... (4 Replies)
Discussion started by: swati
4 Replies

3. AIX

IVM Storage Virtual disk problem

Hi, When I try to create a virtual disk in IVM ( integrated Virtual Machine VIO ) I get this message Problems occurred while processing the data. A summary of all problems for this page are listed below. Additional details for each problem may be located next to the field causing the... (0 Replies)
Discussion started by: filosophizer
0 Replies

4. Solaris

problem with storage error

Hi gurus I don't understand the below messages as what is going on with my storage Plz kindly suggest what could be the problem Script started on Tue 12 May 2009 09:22:13 AM GMT OMP-root-/salil> uptime 9:22am up 19:44, 2 users, load average: 0.10, 0.08, 0.08 OMP-root-/salil> uname -a... (4 Replies)
Discussion started by: girish.batra
4 Replies

5. Solaris

Problem with storage

In the /var/adm/messages, i am getting the following error : Apr 16 23:49:37 inijsce1 EV_AGENT: Time Stamp 04/16/09 23:07:23 Event Number 2580 Severity Error Host inijscx33-adm Storage Array 6ASL102123 SP N/A SoftwareRev 6.19.1 (3.0) Unknown Error 2.19.0.300.5.027 Description Storage Array... (3 Replies)
Discussion started by: sundar3350
3 Replies

6. Solaris

Sun storage L7 Problem

Dear Expert , We have L7 , when we power on we see on lcd messages "drive Post E" , According sun Doc SunSolve , there problem picker or Driver , I try move slot to slot successfully, On Lcd panel i can not see load drive (look like any inside tape in drive , but when i am select eject menu,... (0 Replies)
Discussion started by: hadibn
0 Replies

7. UNIX for Advanced & Expert Users

strange pid and ppid problem

Hi all, Please look into the following code : int main() { char command; int pid, ppid; ppid = getpid(); /* Get the parent pid */ pid = fork(); /* Fork */ if ( pid ==0 ) { sprintf( command, " gdb a.out %d ", ppid ); printf( "Command line is %s\n", command ); system( command... (3 Replies)
Discussion started by: asvija
3 Replies

8. Linux

Some problem about usb mass storage device

Dear linuxers, I have a usb mess storage device. My OS is rh as3 update2. Each time I use the command mount -t vfat /dev/sda1 /mnt/usb I got the error "the device is not a valid block device". I found from google that I should install the module sd_mod I use the command insmod sd_mod... (2 Replies)
Discussion started by: niukun
2 Replies
Login or Register to Ask a Question