1833017 Members
2321 Online
110048 Solutions
New Discussion

Re: wait usage

 
SOLVED
Go to solution
dictum9
Super Advisor

wait usage


I am stopping an SAP application via a shutdown script, and then I want to unmount its filesystems.

I want to make sure the application shutdown script completes successfully so that I won't have any issues unmounting the filesystems.

How can I use the "wait" command for this purpose?

I've always used "sleep" previously but wait seems to be smarter.
5 REPLIES 5
Pete Randall
Outstanding Contributor
Solution

Re: wait usage

The key to this would be to store the PID of the application in a file during startup, then using the wait command in your shutdown script, referencing the PID file.

wait `cat /tmp/PIDfile`

By the way, wait only works on background processes so this may not be exactly what you wanted.


Pete

Pete
Laurent Menase
Honored Contributor

Re: wait usage

Hi
wait can wait for a background process exit.

so if you do
unmount /myfilesys &
echo unmounting
wait
echo umount result$?

or
unmount /myfilesys &
umntpid=$!
echo unmounting
wait $umntpid
echo unmount result $?



James R. Ferguson
Acclaimed Contributor

Re: wait usage

Hi:

If you are simply running syhcnronous tasks:

#/usr/bin/sh
/myshutdown_thing
[ $? -eq 0 ] && echo "success!" || { echo "I failed!"; exit 1; }
echo "now unmounting"

...

Regards!

...JRF...
dictum9
Super Advisor

Re: wait usage

I am not sure what you mean by synchronous, I am running everything in a script:
the shutdown command
and then the umount

I presume the above about exit code still applies.
James R. Ferguson
Acclaimed Contributor

Re: wait usage

Hi (again):

> I am not sure what you mean by synchronous.

Yes, one process after the other, seriallly, rather than in parallel. For example:

# cat ./parallel
#!/usr/bin/sh
( sleep 20; date ) &
T1=$!
echo "task-1 pid=${T1} started"
( sleep 10; date ) &
T2=$!
echo "task-2 pid=${T2} started"
wait ${T1}
wait #{T2}
echo "...finally..."

Regards!

...JRF...