PDA

View Full Version : monitoring processes programatically



idigitall
December 30th, 2009, 10:54 AM
Hi, I'm not sure if this is the correct forum to post this but...

I have a script that launches two processes (process data) into the background simultaneously.
I have another script that also launches two (different) processes (generate graphs) into the background, simultaneously.
The second script can only be run when the first two processes are complete.
How can I check, in one script that controls it all, when the first two processes are done so that the next two processes can be started?

I'd prefer this done in a bash script..

kwyto
December 30th, 2009, 11:12 AM
execute the processes that generates the data first then execute the other two later. also, look at concurrent programming. may give a little insight in the matter.

idigitall
December 30th, 2009, 11:43 AM
yeah thanks but I don't want to rewrite stuff concurrently.

I just want a bash script way of:
./launch1.sh & (save process id in pid1)
./launch2.sh & (save process id in pid2)
while ((kill -0 pid1 != 1) && (kill -0 pid2 !=1))
sleep(5 minutes)
wend
./launch3.sh &
./launch4.sh &

I just don't know which bash commands return the processid and can be used the way I need. If anyone else has an idea, a reply would be much appreciated.

kwyto
December 30th, 2009, 01:16 PM
pid=$! //pid of the last process ran
pid=$$ //pid of the current process

check this tutorial (http://www.linuxtopia.org/online_books/advanced_bash_scripting_guide/internalvariables.html)

idigitall
December 30th, 2009, 03:24 PM
great tut, thanks

sujoy
December 30th, 2009, 04:08 PM
rather you can redesign your first script for a pre-exit hook, and attach the second script to that