[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-bash] Does the parent get the trap signal when the child is runnin
From: |
Peng Yu |
Subject: |
[Help-bash] Does the parent get the trap signal when the child is running in the foreground? |
Date: |
Mon, 10 Dec 2018 11:25:36 -0600 |
Hi,
I am not sure if I understand the traps related with parent and child
processes correctly.
I press Ctrl-C 5 times. The child gets SIGINT 5 times and the parent
gets 1 once. But since Ctrl-C triggers SIGINT for the process group
whose leader is the process started by main1.sh, why main1.sh only
gets one signal? Thanks.
$ cat main1.sh
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:
echo "$$"
trap '((++count)); echo SIGINT trigger in $0 $count times!; exit' SIGINT
./script.sh
$ cat script.sh
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:
echo "$$"
trap '((++count)); echo SIGINT trigger in $0 $count times; if
((count==5)); then exit; fi' SIGINT
while true
do
sleep 1
done
$ ./main1.sh
85799
85814
^CSIGINT trigger in ./script.sh 1 times
^CSIGINT trigger in ./script.sh 2 times
^CSIGINT trigger in ./script.sh 3 times
^CSIGINT trigger in ./script.sh 4 times
^CSIGINT trigger in ./script.sh 5 times
SIGINT trigger in ./main1.sh 1 times!
--
Regards,
Peng
- [Help-bash] Does the parent get the trap signal when the child is running in the foreground?,
Peng Yu <=