Ctrl+C does not work in gnome-terminal

27,014

Solution 1

Try to do this

$ stty sane

and see if it fixes the problem, also check if the intr is set correctly using

$ stty -a

If you find that intr is set to something different than ^C, then you can also fix it by typing

$ stty intr ^v^c

Solution 2

The default settings in gnome-terminal binds the Ctrl-C and Ctrl-V keys to emulate the copy-and-paste behaviour of Windows. It was meant to be a feature not a bug :)

To disable this, at the gnome-terminal,

  1. navigate to Menubar -> Edit -> Keyboard Shortcuts
  2. click on the Ctrl+C in the Shortcut Key column until you see New Accelerator....
  3. press the Backspace or Delete key to disable the key binding
  4. verify that Disabled now appear in the Shortcut Key column.

Note that this change will be immediately effective on all gnome-terminals.

Tip: gnome-terminal --show-menubar will force gnome-terminal to show the Menubar if it is not shown.

Solution 3

Since it looks like a broken gnome-terminal configuration, you can try letting it restore the defaults using

mv .gconf/apps/gnome-terminal{,-BROKEN}

(You'll need to re-start the terminal to see the effects.)

If everything is fine after that, do a rm -rf .gconf/apps/gnome-terminal-BROKEN.

Solution 4

I'm going to take a guess here: Ctrl-C does work, but because ps -e takes a long time to run relative to the rest of the script, that all you do is send SIGINT to the "ps" process. "ps" exits, and the script picks right up with another iteration through the loop code.

Do a sleep 10 in your bash window, while it runs, control-C it. See if that works. If it does, run your original script, and control-C it multiple times. Sooner or later, you'll get lucky and the bash process that interprets the script will get the SIGINT.

Solution 5

When I looked at my shortcuts for terminal I see that the shortcut for "copy" is set to Control+C. So I changed it to Control+Shift+V (for copying).

Now everything is working.

Be sure to check

stty -a

and make sure intr is set to ^C before checking the shortcuts.

Share:
27,014

Related videos on Youtube

Cees
Author by

Cees

Updated on September 18, 2022

Comments

  • Cees
    Cees over 1 year

    On my Linux host, Ctrl+C does not seem to work and I do not know how to proceed to make it work. I am using Ubuntu 10.04 with bash 4.1.5(1), and working in Gnome-terminal.

    When I pressed Ctrl+C while this script was running, it did not cause it to quit.

    #!/bin/bash
    for i in `seq 500`
    do
            ps -e > /dev/null
            echo $i
    done
    
    • Admin
      Admin over 12 years
      What do you mean by “does not work”? Where did you press that key, what did you expect to happen, what actually happened?
    • Admin
      Admin over 12 years
      Maybe you can describe further details of why you think that Ctrl-C does not work -- there are certain kernel level things which is not interruptible -- for example a process hanging waiting for a (failed) NFS answer can frequently not be interrupted
    • Admin
      Admin over 12 years
      I updated my answer. Basically Ctrl C did not terminate a script, that I think should be terminated on doing Ctrl C.
    • Admin
      Admin over 12 years
      Does stty -a output contain intr=^C? How do you run the script?
    • Admin
      Admin over 12 years
      Please do not cross-post questions. Choose the site you want to ask on, and tailor it to that site.
    • Admin
      Admin over 12 years
      You're right that the script should be terminated if you press Ctrl+C. In what terminal did you do this? Does it happen in another terminal? What happens if you run sleep 5 and then press Ctrl+C?
    • Admin
      Admin over 12 years
      Its regular terminal in Ubuntu. It is /dev/pts/0 if that helps. It happens in any terminal on my computer. If I do sleep 5 and do Ctrl C nothing happens. Nothing is printed to the console also.
    • Admin
      Admin over 12 years
      I run the script by doing ./hello.sh
    • Admin
      Admin over 12 years
      @abc: have you tried to use a different terminal emulator (xterm, rxvt, …)?
    • Admin
      Admin over 12 years
      when I tried using xterm I was able to Ctrl C sleep 10. But with gnome-terminal Ctrl C on sleep 10 did not work. Why is that ?
    • Admin
      Admin over 12 years
      So using gnome-terminal Ctrl C works but Ctrl c does not. So to interrupt sleep 10 if I do Ctrl + Shift + c it works. But doing Ctrl + c does not work. Why is it case sensitive.
  • Cees
    Cees over 12 years
    This did not help. stty -a shows "intr = ^C" ( without the quotes)
  • Cees
    Cees over 12 years
    Do I have to type the ^ character or press the Ctrl key?
  • Soren
    Soren over 12 years
    you just have to press the Ctrl key (^ is short for Ctrl-)
  • Soren
    Soren over 12 years
    Maybe you can describe further details of why you think that Ctrl-C does not work -- there are certain kernel level things which is not interruptible -- for example a process hanging waiting for a (failed) NFS answer can frequently not be interrupted
  • Cees
    Cees over 12 years
    I added more details to my question. Basically Ctrl C is not terminating a script that I am running, which I expect to be terminated on Ctrl C.
  • Cees
    Cees over 12 years
    Ctrl C on sleep 10 does not work either.
  • Cees
    Cees over 12 years
    So using gnome-terminal Ctrl C works but Ctrl c does not. So to interrupt sleep 10 if I do Ctrl + Shift + c it works. But doing Ctrl + c does not work. Why is it case sensitive.
  • Cees
    Cees over 12 years
    So using gnome-terminal Ctrl C works but Ctrl c does not. So to interrupt sleep 10 if I do Ctrl + Shift + c it works. But doing Ctrl + c does not work. Why is it case sensitive.
  • Tom St
    Tom St almost 4 years
    not sure why this answer was minused, its really good :)