Discussion:
[Help-bash] How send signals to coproc automatically?
Peng Yu
2018-02-12 17:36:50 UTC
Permalink
Hi,

The trap in the coproc can be triggered. But when I type ctrl-c to
terminate the current program. It will not be triggered. Is there a
way to let the coproc get signals from the main program? Thanks

$ cat main.sh
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:

trap 'echo main' EXIT
coproc {
seq 3
trap 'echo mycoproc' EXIT
}
exec 3>&"${COPROC[0]}"

sleep 1
while IFS=$'\t' read -r -u 3 line
do
printf '%s\n' "$line"
done

$ ./main.sh
1
2
3
mycoproc
$ ./main.sh
^Cmain
--
Regards,
Peng
Chet Ramey
2018-02-12 19:22:13 UTC
Permalink
Post by Peng Yu
Hi,
The trap in the coproc can be triggered. But when I type ctrl-c to
terminate the current program. It will not be triggered. Is there a
way to let the coproc get signals from the main program? Thanks
Why not just send a signal to $COPROC_PID using `kill'?
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU ***@case.edu http://tiswww.cwru.edu/~chet/
Peng Yu
2018-02-12 20:45:34 UTC
Permalink
I'd like to to make the behavior consistent whether there is coproc or not.
Post by Chet Ramey
Post by Peng Yu
Hi,
The trap in the coproc can be triggered. But when I type ctrl-c to
terminate the current program. It will not be triggered. Is there a
way to let the coproc get signals from the main program? Thanks
Why not just send a signal to $COPROC_PID using `kill'?
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
--
Regards,
Peng
Loading...