Background processes receive SIGINT even though they shouldn't
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Configuration Information [Automatically generated, do not change]: Machine: i386 OS: linux-gnu Compiler: i386-redhat-linux-gcc Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='i386' - -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i386-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 - -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O2 -g -pipe - -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -m32 -march=i386 -mtune=pentium4 - -fasynchronous-unwind-tables uname output: Linux tyrannosaurus 2.6.14-1.1656_FC4 #1 Thu Jan 5 22:13:22 EST 2006 i686 i686 i386 GNU/Linux Machine Type: i386-redhat-linux-gnu Bash Version: 3.0 Patch Level: 16 Release Status: release Description: In some cases, background processes receive SIGINT from the terminal where it was started even though the manual states that such processes are immune to keyboard-generated signals. This is best explained by trying out the example below. There is a reason for the seemingly complex sleep arrangement in test2. This is really a condensed version of a much larger script, but it still demonstrates the problem well. Repeat-By: 1) Create two shell scripts, test1 and test2, which are supplied below: test1: ### START SCRIPT ### #!/bin/bash test2 & while /bin/true; do echo test1 sleeping sleep 5 done ### END SCRIPT ### test2: ### START SCRIPT ### #!/bin/bash while /bin/true; do echo test2 sleeping sleep 5 & SLEEP_PID=$! wait $SLEEP_PID unset SLEEP_PID done ### END SCRIPT ### 2) Run test1 from the terminal 3) Interrupt it with CTRL-C 4) Notice that test2 was also interrupted. This can also be done by finding the PID of test2 and letting strace attach to the process before interrupting test1. Strace will report that a SIGINT was caught. Fix: N/A -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.1 (GNU/Linux) Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org iD8DBQFDw4016sVa+fPBo9YRAj0qAJ49V67E1gVRq+1sfKlx9ndYacEGkwCgrRoA LvtXYfV3IZaOdFfiEypResw= =gAR/ -END PGP SIGNATURE- ___ Bug-bash mailing list Bug-bash@gnu.org http://lists.gnu.org/mailman/listinfo/bug-bash
Re: Background processes receive SIGINT even though they shouldn't
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Chet Ramey wrote: > I think you're slightly misunderstanding how job control and process > groups interact. Okay. > When you run test1 from an interactive shell with job control enabled, > it is placed into a separate process group. The terminal's foreground > process group is set to test1's process group, which means that group > receives keyboard-generated signals like SIGINT. > > The shell started to run test1 is not interactive, so job control is > disabled. This means that all processes started by test1 and its > descendants are placed into the same process group. Since this is > the terminal's foreground process group, these processes receive the > SIGINT. I see, thanks. Then I have another question: Why does test2 below fail to trap SIGINT when started by test1? It works when I run test2 directly. test1 (for reference): ### START SCRIPT ### #!/bin/bash test2 & while /bin/true; do echo test1 sleeping sleep 5 done ### END SCRIPT ### test2 (updated): ### START SCRIPT ### #!/bin/bash function shutdown { echo "Shutting down test2..." exit 0 } trap shutdown SIGINT while /bin/true; do echo test2 sleeping sleep 5 & SLEEP_PID=$! wait $SLEEP_PID unset SLEEP_PID done ### END SCRIPT ### Thanks in advance. Regards Ingemar -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.1 (GNU/Linux) Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org iD8DBQFDx3Fd6sVa+fPBo9YRAmUoAJ9ARnxH4rirGcfegpg20/QxWozyBgCfa98o UE1JbSi4kq6jDM9Q8iOZNLY= =pxe6 -END PGP SIGNATURE- ___ Bug-bash mailing list Bug-bash@gnu.org http://lists.gnu.org/mailman/listinfo/bug-bash
Re: Background processes receive SIGINT even though they shouldn't
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Chet Ramey wrote: > I am looking at the apparent contradiction between this and the > previous answer. It might be that the shell begun to run test2 > undoes the signal ignoring performed when it is initally forked. > It seems like somewhere along the line the SIGINT handling is being > changed. Any progress yet? I found a way to solve the problem anyway, using the setsid command to run test2 from test1. Regards Ingemar -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.1 (GNU/Linux) Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org iD8DBQFD3hE46sVa+fPBo9YRAgOXAJ9chAfPqOCYvZrIQOOUWdYuyJoRVQCgo8IQ 93kZCfq4IW/pVetyWJ7VFWU= =kmdf -END PGP SIGNATURE- ___ Bug-bash mailing list Bug-bash@gnu.org http://lists.gnu.org/mailman/listinfo/bug-bash