Configuration Information [Automatically generated, do not change]: Machine: x86_64 OS: linux-gnu Compiler: gcc Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64' -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-redhat-linux-gnu' -DCONF_VENDOR='redhat' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H -I. -I. -I./include -I./lib -D_GNU_SOURCE -DRECYCLES_PIDS -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic uname output: Linux fedora14 2.6.35.10-74.fc14.x86_64 #1 SMP Thu Dec 23 16:04:50 UTC 2010 x86_64 x86_64 x86_64 GNU/Linux Machine Type: x86_64-redhat-linux-gnu
Bash Version: 4.2 Patch Level: 8 Release Status: release Description: I am a programmer working in Japan. I encountered an incompatibility between bash 4.2 and 4.1. --- cut here --- #!/bin/bash # tset_trap.bash RESET_SIGTERM="$1" subshell() { ID1=$BASH_SUBSHELL if [ -n "$RESET_SIGTERM" ] ; then #trap "" SIGTERM ### workaround trap - SIGTERM ### doubt echo "reset SIGTERM" fi ( # exec subshell SELF_PID=$! [ -n "$BASHPID" ] && SELF_PID=$BASHPID local -a p=(`head -1 /proc/$SELF_PID/stat`) PARENT=${p[3]} ID2=$BASH_SUBSHELL echo "ROOT=$ROOT_PID SUB${ID1}=$PARENT SUB${ID2}=$SELF_PID" grep -H SigIgn /proc/$PARENT/status grep -H SigIgn /proc/$SELF_PID/status pstree -p $ROOT_PID ) & wait } ROOT_PID=$$ trap "" SIGTERM grep -H SigIgn /proc/$ROOT_PID/status subshell | gawk '{printf("%s %s\n", strftime("%F %T"), $0) ; fflush()}' & trap - SIGTERM wait ---------------- Repeat-By: Please run 'test_trap.bash' . The next is a result on bash 4.2. # rpm -q bash bash-4.2.8-1.fc15.x86_64 # ./test_trap.bash 1 /proc/5399/status:SigIgn: 0000000000004004 2011-03-21 21:16:15 reset SIGTERM 2011-03-21 21:16:15 ROOT=5399 SUB1=5401 SUB2=5403 2011-03-21 21:16:15 /proc/5401/status:SigIgn: 0000000000004006 2011-03-21 21:16:15 /proc/5403/status:SigIgn: 0000000000004006 2011-03-21 21:16:15 test_trap.bash(5399)-+-gawk(5402) 2011-03-21 21:16:15 `-test_trap.bash(5401)---test_trap.bash(5403)---pstree(5407) We can not reset SIGTERM in subshell. On bash 4.1 or older version, we can reset it. The next is a result on bash 4.1. # rpm -q bash bash-4.1.7-3.fc14.x86_64 # ./test_trap.bash 1 /proc/5634/status:SigIgn: 0000000000004004 2011-03-21 21:24:07 reset SIGTERM 2011-03-21 21:24:07 ROOT=5634 SUB1=5636 SUB2=5638 2011-03-21 21:24:07 /proc/5636/status:SigIgn: 0000000000000006 2011-03-21 21:24:07 /proc/5638/status:SigIgn: 0000000000000006 2011-03-21 21:24:07 test_trap.bash(5634)-+-gawk(5637) 2011-03-21 21:24:07 `-test_trap.bash(5636)---test_trap.bash(5638)---pstree(5642) On Linux, we can see signal mask in /proc/<PID>/status. Best Regards, s-taka (Satoshi Takahashi)