On Wed, Jun 22, 2016 at 10:34:59AM +0100, John Lawlor wrote:
> If I do the following:
> 
> bash -c "ping 127.0.0.1 > $HOME/console.log"  &

> Now if I kill bash:
> 
> Bash is killed but not the child ping process. I was expecting that to be 
> killed also.

Not a bug.  If you want a signal (e.g. SIGTERM) to be caught by bash
and propagated to bash's children, you need to catch it and send it
to your children.  This also means you have to run your children as
background processes and capture their PIDs.  Otherwise, if the child is
a foreground process, bash will not receive the signal until the child
exits on its own.

For example:

#!/bin/bash
unset pid
trap '[[ $pid ]] && kill $pid' EXIT
ping 127.0.0.1 >~/console.log &
pid=$!
wait

Reply via email to