Hi. I'm working with two BASH shells in order to perform two tasks. For simplicity, suppose that at Shell #1 I'm executing this program:
sleep 100
whose PID is 263. Meanwhile Shell #2 is waiting for its termination to follow with a second one.
I tried with:
wait 263
# Script for second task...
at Shell #2, but it throws me this message:
-bash: wait: pid 263 is not a child of this shell
Any idea of how to perform this operation?
Many thanks in advance.
Wouldn't it be easier to run your (first) script in the background and keep an eye on the - foregrounded - process table of the (only) shell ...
[house@leonov] sh test.bash &
[house@leonov] ps aux | grep 'sh' | grep 'test'
house 27118 11400 1588 pts/3 sh test.bash
Thanks for the reply. In this case I have to work on two shells, since I'm running OpenSees and Matlab at the same time.
What I need is to emulate the "wait" command in order to perform my request.
Thanks in advance.
Scott
4
Hi.
You could try something like this:
myWait
======
while [ "$(ps -ef | awk '$2 == '${1:-X})" ]; do sleep 3; done
Pass in the process ID to wait for (i.e. "myWait 5657" or "./myWait 5657")
Many thanks for the reply. Yes, my first try was:
while [ "$(ps c | grep 263)" ]; do sleep 1; done
But I would like to see a better solution, like the wait command.
Thank you!