In general I support G-Man's answer. I'd like to introduce a quick solution that may be enough in some circumstances.
Let the three executables be foo
, bar
and baz
. The assumptions:
- you can run them by hand;
- you run all of them as the same user;
- you run at most one
foo
, one bar
and one baz
at any given time.
Instead of foo
run foo ; killall bar 2>/dev/null
.
Instead of bar
run bar ; killall baz 2>/dev/null
.
Instead of baz
run baz ; killall foo 2>/dev/null
.
If you want to run foo
in background, the correct syntax is like:
{ foo ; killall bar 2>/dev/null ; } &
Similarly with bar
and baz
. This way you can run them from a single shell if you wish.
The solution scales to any reasonable number of processes. When one process terminates, a daisy chain of killall
will be triggered. This will eventually play thrash metal kill 'em all.
Note you shouldn't start a new set of processes until you know for sure this killing chain is finished.