On Thu, 4 May 2006, Moshe Kaminsky wrote:

#!/bin/sh
trap 'kill 0;exit' TERM
echo "before"
( sleep 30; echo inside )
echo "after"

No use. trap will wait till the running child is completed, which is not
what
I want (as reply of Hans-Werner).


Funny, I just tried the same, and it worked. It also didn't print any
"after" (appropriately, since the sig handler includes 'exit'), and I
didn't find any sleep process. Maybe it was from some different
experiment?

Just tried again, with /bin/bash and with /bin/sh (and sleep 3000).
It outputs "before" and hangs while sleeping. Sending TERM to the parent
has no _visible_ immediate effect. After sending TERM to the "sleep
3000" process, the output is
        ./t.sh: line 5:  2572 Terminated              sleep 3000
        inside
and the processes exit, which means (I think) that the trap only gets
executed after the child exits (in this case, due to the TERM received
by the "sleep..." process).
I tried with a sleep interval of 20 seconds and send TERM as before to
the parent, but not to the child. It exits _after_ 20 seconds, with output
        before
        inside
This seems to agree with the comment of Hans-Werner about the man page.
Can't imagine why it's different to you. Is /bin/sh a symlink to
/bin/bash, or are you using another shell?


--
Jorge Almeida
--
gentoo-user@gentoo.org mailing list

Reply via email to