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.
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:
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:
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..
@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.
@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).
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
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)
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)
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)
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)
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)
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)
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)
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)
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)