Wait for one processes to complete in a shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Wait for one processes to complete in a shell script
# 8  
Old 06-19-2013
Chances are you can wait for that BG program, as it is in then same job tree/group as your main script. Run ps, grep for the (expanded) BIP $PROCNAME 3 process, and wait for its PID.
# 9  
Old 06-19-2013
you could also do this in c.sh ...
Code:
a.sh && b.sh

# 10  
Old 06-20-2013
Quote:
Originally Posted by RudiC
Chances are you can wait for that BG program, as it is in then same job tree/group as your main script. Run ps, grep for the (expanded) BIP $PROCNAME 3 process, and wait for its PID.
This shouldn't work. You can only "wait" for your children; not your grandchildren or siblings. Since the last thing bip.sh does before exiting is invoke BIP asynchronously, bip.sh returns just after BIP has been started without waiting for it to finish and leaving the process that invoked bip.sh with no way to reap the grandchild's exit status and no direct way to wait for the grandchild to finish.

The obvious fix here is to remove the & at the end of the last line in bip.sh and invoke bip.sh with an & in cases where you want to continue other processing while BIP runs. The shell that invokes bip.sh can then wait for bip.sh to complete using a wait command without operands. But, of course, this may require modifying every other script that calls bip.sh and doesn't want to wait for it to finish.

Similarly, Just Ice's suggestion to use:
Code:
bip.sh && c.sh

won't work if the intent is to wait for the BIP command that was started by bip.sh to finish before starting c.sh because the current version of bip.sh returns without waiting for BIP to finish.

Last edited by Don Cragun; 06-20-2013 at 01:37 AM.. Reason: fixed case: bip -> BIP.
This User Gave Thanks to Don Cragun For This Post:
# 11  
Old 06-20-2013
since bip.sh output is redirected to a file on your main script, you may check if any process has this file open to ensure that the file is written. If no process has it open, the next command ( tail) can be started..
# 12  
Old 06-20-2013
@Don Cragun: Right, I should have known better / read the man.
Still you could find the PID using ps, and then check for the existence of your BIP process. Or, have bip.sh report that PID back.
# 13  
Old 06-20-2013
Quote:
Originally Posted by RudiC
@Don Cragun: Right, I should have known better / read the man.
Still you could find the PID using ps, and then check for the existence of your BIP process. Or, have bip.sh report that PID back.
Yes, bip.sh could report the PID back to the caller, but the caller still can't use the wait utility to wait for it to terminate. The caller could repeatedly search ps command output to determine when the grandchild has terminated. But an invocation of wait with the PID of the grandchild as an operand will yield an exit code of 127 from wait indicating that the grandchild is not known to the current shell (i.e., the underlying waitpid() call generated an ECHILD error).
# 14  
Old 06-20-2013
well...i go into a loop and check if a process named a.sh is still going on..if its still running, i wait for two seconds and again check as the same function is being called within itself...ps gives you the list of processes running and grep displays from the standard output the process named a.sh..if there is no process running, it will start the second process and so on...u can google a bit for the other contents used in the script. just let me know if it helped
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script parallel tasks and command to wait untill complete?

Hello, im having bash script with while *** command1 && command2 && command3 && done i want to ask how i can prevent overloading server, by waiting untill all commands complete? any low resources intensive command like "wait" - i dont know if exist? (2 Replies)
Discussion started by: postcd
2 Replies

2. Shell Programming and Scripting

[Solved] Help with shell Script ,wait for some files for some time??

Hi All, I have the requirement that ,i have to write a shell script that job has to wait for a 7 touch files created by another application for 4 hours, if i get all 7 touch files ,i have to send a mail that i jobs are completed, if if it is waiting for more than 4 hours i have to send a mail... (2 Replies)
Discussion started by: Pradeep Shetty
2 Replies

3. Shell Programming and Scripting

In Shell Script Does Second Command Wait For First Command To Complete

Hi All, I have a question related to Shell scripting. In my shell script, I have following two commands in sequence: sed 's/^/grep "^120" /g' $ORIGCHARGEDAMTLIST|sed "s;$;| cut -f$FIELD_NO1 -d '|' | awk '{ sum+=\$1} END {printf (\"%0.2f\\\n\", sum/100)}' >$TEMPFILE mv $TEMPFILE $ORIGFILE... (3 Replies)
Discussion started by: angshuman
3 Replies

4. Shell Programming and Scripting

calling a shell script in background and wait using "wait" in while loop

Hi, I am facing a strange issue, when i call a script from my while loop in background it doesnt go in background, despite the wait i put below the whil loop it goes forward even before the process put in background is completed. cat abc.txt | while read -u4 line do #if line contains #... (2 Replies)
Discussion started by: mihirvora16
2 Replies

5. UNIX for Dummies Questions & Answers

How do you wait for command substitution processes to complete?

When running a command using the >(cmd) syntax in bash how do you wait for the command to complete before moving on in your script? Here is a simple example: zcat largefile.gz | tee >(wc && echo “HELLO”) > /dev/null # I tried wait, here but it doesn't wait for the process in the subshell.... (8 Replies)
Discussion started by: mrvwman
8 Replies

6. Filesystems, Disks and Memory

hdparm + HDIO_DRIVE_CMD(null) (wait for flush complete) failed: Inappropriate ioctl

Hi All, Am finding performance of my SD card using hdparm. hdparm -tT /dev/BlockDev0 /dev/BlockDev0: Timing cached reads: 1118 MB in 2.00 seconds = 558.61 MB/sec HDIO_DRIVE_CMD(null) (wait for flush complete) failed: Inappropriate ioctl for device Timing buffered disk reads: 14... (0 Replies)
Discussion started by: amio
0 Replies

7. Shell Programming and Scripting

wait for 5 seconds in shell script

hi how can i wait for 5 seconds inside my shell script? 'wait 5' command doesnot seem to be working? (2 Replies)
Discussion started by: gopsman
2 Replies

8. Programming

Howto spawn multiple child processes and wait?

As far as I can tell, the bash wait command waits for a logical "AND" of all the child processes. Assuming I am coding in C: (1) What is the function I would use to create multiple bash child process running perl? (2) What is the function I would use to reinvent the bash wait command so I... (4 Replies)
Discussion started by: siegfried
4 Replies

9. Shell Programming and Scripting

Wait for Background Process to complete

I am attempting within a for-loop, to have my shell script (Solaris v8 ksh) wait until a copy file command to complete before continueing. The specific code is: for files in $(<inputfile.lst) do mv directory/$files directory/$files ksh -m -i bg %% wait $! done I am shaky on the... (3 Replies)
Discussion started by: gozer13
3 Replies

10. Shell Programming and Scripting

PERL: wait for process to complete

I'm using PERL on windows NT to try to run an extract of data. I have multiple zip files in multiple locations. I am extracting "*.t" from zip files and subsequently adding that file to one zip file so when the script is complete I should have one zip file with a whole bunch of ".t" files in it. ... (2 Replies)
Discussion started by: dangral
2 Replies
Login or Register to Ask a Question