I want to launch multiple applications (e.g. 3 PDF viewers) in a manner that, if you are done and close one of the windows, all of the applications launched together all close as well. What is the best way to implement this?
The first solution for this I can think up off the time of my head is this: open all 3 programs in a terminal, like so:
program & program & program &. Then, when you close the terminal, the sub-processes will close, too.
The second thing I thought of is programming a shell script to terminate child processes when there are fewer than three of them. Here's a script you can try:
#!/bin/sh program & program & program & while [ $(jobs | wc -l) -gt 2 ]; do sleep 2; done kill $(jobs -p) exit
Do note I have not tested this.