First, let me start out by saying that this doesn't answer your question, but I hope might help clarify what's happening. I suspect that what you think is happening might not really be happening. Consider this simple example:
# The 'writer' reads input from standard input and
# echos it to standard output. It handles SIGINT by
# printing INT to standard output.
$ cat writer
#!/bin/bash
function foo() {
echo "INT"
}
trap foo INT
while read x; do echo $x; done
# The 'reader' reads input from standard input and pipes what is
# read to 'sed', which converts it to upper case. It ignores SIGINT.
# When it receives EOF on standard input, it writes "done".
$ cat reader
#!/bin/bash
trap '' INT
cat | sed -e 's/\(.*\)/\U\1/'
echo "done"
Now, when I run both, piping the output of writer
into reader
:
$ ./writer | ./reader
hello
HELLO
^CINT
^CINT
^CINT
world
WORLD
^D
done
$
The writer
script reads reads from standard input and writes to the standard output – the pipe. The reader
scripts reads from standard input — the pipe — and writes to standard output. When I hit Ctrl-C
, the writer
writes "INT"; the reader
ignores the signal (multiple times). Eventually, I enter Ctrl-D
(EOF), and the writer
terminates. When the reader
receives the EOF, it terminates and writes "done".
Note that the reader
ignores the SIGINT more than once, and that neither the pipe nor sed
is interrupted when the writer
handles the SIGINT.
ps
and see thatsed
was indeed interrupted?