Skip to main content
+more tests
Source Link
  • Running the following command from another terminal while the script is running:

     kill -INT <process> 

    didn't accomplish anything, even while running the kill command as root. Running

     kill -HUP <process> 

    terminated the script as expected.

  • I attempted to trap the signal by adding the following lines to my script:

     trap "echo hi" SIGINT trap "echo lo" SIGHUP 

    Hitting CTRL-C or running kill -INT <process> as above showed no reaction. Running kill -HUP <process> as above did echo "lo" as expected.

  • I have tried running the script in the following ways

     /bin/sh /path/to/test.sh /bin/bash /path/to/test.sh /path/to/test.sh cd /path/to; test.sh 

    No difference.

  • As suggested by @mosvy in the comments, I tried running it through perl as follows:

     perl -e '$SIG{INT}="DEFAULT"; exec @ARGV or die "exec: $!"' /path/to/test.sh 

    This, for some reason, did work.

  • Running the following command from another terminal while the script is running:

     kill -INT <process> 

    didn't accomplish anything, even while running the kill command as root. Running

     kill -HUP <process> 

    terminated the script as expected.

  • I attempted to trap the signal by adding the following lines to my script:

     trap "echo hi" SIGINT trap "echo lo" SIGHUP 

    Hitting CTRL-C or running kill -INT <process> as above showed no reaction. Running kill -HUP <process> as above did echo "lo" as expected.

  • Running the following command from another terminal while the script is running:

     kill -INT <process> 

    didn't accomplish anything, even while running the kill command as root. Running

     kill -HUP <process> 

    terminated the script as expected.

  • I attempted to trap the signal by adding the following lines to my script:

     trap "echo hi" SIGINT trap "echo lo" SIGHUP 

    Hitting CTRL-C or running kill -INT <process> as above showed no reaction. Running kill -HUP <process> as above did echo "lo" as expected.

  • I have tried running the script in the following ways

     /bin/sh /path/to/test.sh /bin/bash /path/to/test.sh /path/to/test.sh cd /path/to; test.sh 

    No difference.

  • As suggested by @mosvy in the comments, I tried running it through perl as follows:

     perl -e '$SIG{INT}="DEFAULT"; exec @ARGV or die "exec: $!"' /path/to/test.sh 

    This, for some reason, did work.

+test results from comment thread
Source Link

###Other things tried (recording here to get them out of comment threads)

  • Running the following command from another terminal while the script is running:

     kill -INT <process> 

    didn't accomplish anything, even while running the kill command as root. Running

     kill -HUP <process> 

    terminated the script as expected.

  • I attempted to trap the signal by adding the following lines to my script:

     trap "echo hi" SIGINT trap "echo lo" SIGHUP 

    Hitting CTRL-C or running kill -INT <process> as above showed no reaction. Running kill -HUP <process> as above did echo "lo" as expected.


###Other things tried (recording here to get them out of comment threads)

  • Running the following command from another terminal while the script is running:

     kill -INT <process> 

    didn't accomplish anything, even while running the kill command as root. Running

     kill -HUP <process> 

    terminated the script as expected.

  • I attempted to trap the signal by adding the following lines to my script:

     trap "echo hi" SIGINT trap "echo lo" SIGHUP 

    Hitting CTRL-C or running kill -INT <process> as above showed no reaction. Running kill -HUP <process> as above did echo "lo" as expected.

Formatted text.
Source Link
Paulo Tomé
  • 3.9k
  • 6
  • 29
  • 40

This, for the most part, works as expected. However, on one particular user account (which is of course the account I want this to run under) the CTRL-CCTRL-C key combination doesn't seem to be sending an interrupt signal to the script, which means it runs forever until I kill it in another terminal.

The first thing I checked was whether the .profile for this account had somehow undefined stty intr, but that is not the case (and explicitly adding the line stty intr "^c"

stty intr "^c" 

to my script didn't help, neither did setting the escape code to something different). The .profile.profile also does not appear to be trapping any signals anywhere. This problem occurs whether I sudo into the account or log in directly. CTRL-CCTRL-C seems to work as expected when I run other commands (e.g. ping) from the command line.

CTRL-CCTRL-C interrupts the script as expected if I run it as root, or if I run it while logged in under a different unprivileged account. Creating an entirely new unprivileged account with a default .profile, it doesn't work. This is all using the same terminal installation and settings (PuTTY), so it doesn't appear to be a case of the terminal itself somehow intercepting or mangling the signals.

This, for the most part, works as expected. However, on one particular user account (which is of course the account I want this to run under) the CTRL-C key combination doesn't seem to be sending an interrupt signal to the script, which means it runs forever until I kill it in another terminal.

The first thing I checked was whether the .profile for this account had somehow undefined stty intr, but that is not the case (and explicitly adding the line stty intr "^c" to my script didn't help, neither did setting the escape code to something different). The .profile also does not appear to be trapping any signals anywhere. This problem occurs whether I sudo into the account or log in directly. CTRL-C seems to work as expected when I run other commands (e.g. ping) from the command line.

CTRL-C interrupts the script as expected if I run it as root, or if I run it while logged in under a different unprivileged account. Creating an entirely new unprivileged account with a default .profile, it doesn't work. This is all using the same terminal installation and settings (PuTTY), so it doesn't appear to be a case of the terminal itself somehow intercepting or mangling the signals.

This, for the most part, works as expected. However, on one particular user account (which is of course the account I want this to run under) the CTRL-C key combination doesn't seem to be sending an interrupt signal to the script, which means it runs forever until I kill it in another terminal.

The first thing I checked was whether the .profile for this account had somehow undefined stty intr, but that is not the case (and explicitly adding the line

stty intr "^c" 

to my script didn't help, neither did setting the escape code to something different). The .profile also does not appear to be trapping any signals anywhere. This problem occurs whether I sudo into the account or log in directly. CTRL-C seems to work as expected when I run other commands (e.g. ping) from the command line.

CTRL-C interrupts the script as expected if I run it as root, or if I run it while logged in under a different unprivileged account. Creating an entirely new unprivileged account with a default .profile, it doesn't work. This is all using the same terminal installation and settings (PuTTY), so it doesn't appear to be a case of the terminal itself somehow intercepting or mangling the signals.

Source Link
Loading