bug-bash
[Top][All Lists]
Advanced

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

Re: trap behaviour different depending on stdio redirection?


From: Andreas Schwab
Subject: Re: trap behaviour different depending on stdio redirection?
Date: Wed, 13 Mar 2013 15:49:14 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Charles Smith <address@hidden> writes:

> Hi, I have the following script, which just kills itself.
> It sets a trap, but only takes it if the output is not redirected.

It does take it, but the output goes nowhere.

> Can anybody explain to me why?

You are killing the whole process group, which includes both sides of
the pipeline.

> When I run it with stdio redirection, the script is terminated at the kill:
>
>   $ bash -x  test17  2>&1 | tee 0312-29.out
>   + trap 'echo caught signal 2' 2
>   + trap -p
>   trap -- 'echo caught signal 2' SIGINT
>   + grep 8714
>   + ps -eo pid,pgid,cmd
>    8714  8714 bash -x test17
>    8715  8714 tee 0312-29.out
>    8716  8714 ps -eo pid,pgid,cmd
>    8717  8714 grep 8714

These are all the processes you will kill next.

> $ echo $?
> 130

This is the exit code of the tee process, which died of signal 2 before
it could receive the rest of the output through the pipe.  If you don't
redirect stderr you will see what the shell executed after the pipe was
broken.

Andreas.

-- 
Andreas Schwab, address@hidden
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



reply via email to

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