Reputation: 1515
I have a script like this:
#!/bin/sh
exec ./cmd1&
exec ./cmd2
If I kill the script only cmd2
is killed, cmd1
keeps running.
Is it possible that both processes quit automatically?
Upvotes: 2
Views: 1042
Reputation: 164
do not do second exec
(the first one is redundant, too) but leave the shell wait for it. killing the shell may kill the commands; if not - then:
trap 'kill -15 $kids; exit 143' TERM
cmd1 &
kids=$!
cmd2 &
kids="$kids $!"
wait
Upvotes: 3