bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Possible bash bug?


From: Greg Wooledge
Subject: Re: Possible bash bug?
Date: Wed, 22 Jun 2016 09:45:11 -0400
User-agent: Mutt/1.4.2.3i

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

[Prev in Thread] Current Thread [Next in Thread]