ctrl-c does not send INT to all processes under foreground job
From:
Ryan Ruan
Subject:
ctrl-c does not send INT to all processes under foreground job
Date:
Wed, 19 Mar 2014 04:07:06 +0000
Hello, guys:
It is said that "ctrl-C sends INT to ALL processes under foreground job", but i
found a weird phenomenon.
I have not read source code yet, but it does not seem to ascribe to what
specification says.
Test code is like:
1 trap "echo hello world $1" 2
2 sleep 10000
3 /bin/bash $0 $(( $1 + 1 ))
4 echo "$1 go to sleep"
5 sleep 1000
6 echo "$1 exit "
When I run ./test.sh on the console, the process (/bin/bash test.sh) is stuck
at line 2.
Then I input Ctrl-C, the result is that the code is interrupted at line 2 and
goes to execute line 3, thus generate a new process (/bin/bash test.sh 1).
At the same time, the first process (/bin/bash test.sh) is stuck at line 3
waiting for process '/bin/bash test.sh 1' to finish.
At this time, I input Ctrl-C again, and generate process '/bin/bash test.sh 2',
and i think process '/bin/bash test.sh 1' SHOULD BE SENT signal INT now. So I
kill process '/bin/bash test.sh 2' by doing 'kill -9 <pid>'.
What amazes me is that process '/bin/bash test.sh 1' did not trap INT this
time, because "hello world 1" is not printed out. So it seems the process did
not receive INT before.
How can this be? Is it a bug?
Br/
Ruan