Question

If I have a parent process which forks to 5 child processes in the background and a wait, ie.

job1.sh& job2.sh& job3.sh& job4.sh& job5.sh& wait

Would it be possible to find out which of the jobs I have ran finished last? I want this to be fully automated by a script. Log files would give me the answer but a requirement is that it should be automated.

I am currently working on AIX. I am thinking that it may be possible to use signals to do this but I haven't had enough exposure to know if this is valid.

Any help is greatly appreciated!

Many thanks and happy coding

Was it helpful?

Solution

How about this:

( job1.sh ; echo 1 > /tmp/HAPPY )&
( job2.sh ; echo 2 > /tmp/HAPPY )&
( job3.sh ; echo 3 > /tmp/HAPPY )&
( job4.sh ; echo 4 > /tmp/HAPPY )&
( job5.sh ; echo 5 > /tmp/HAPPY )&
wait
read last_child < /tmp/HAPPY

Note that this is not 1000000% bullet proof because two jobs can finish up sooo close together that the echo's will get intertwined. You could complicate this by adding the old fashioned file locking that is possible via shell scripting if you really need to or you could add some smarts after reading last_child to parse it if it is not a simple integer in the range that you are looking for. I think I would just go with the above until it is proven to be too crude... the case could easily never come up.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top