May
17th,
2011
Yes, this probably doesn’t count as a good idea… but sometimes you have to use bash to do these kind of things - so I might as well explain how I did it. Most of this work was based on someone else’s hints and tips, but I’m afraid I can’t find the references any more…
The concept is quite simple. Launch a series of jobs in parallel, in the background, recording the PID of each one. Also run a timer function, which when it times out sends SIGALRM to the parent. the parent has a trap, listening for the signal, and if it receives it, it actively kills all its children. Otherwise, the children exit cleanly, and the parent tidies up.