Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
share|improve this question
2  
What do you mean by “does not work”? Where did you press that key, what did you expect to happen, what actually happened? –  Gilles Aug 11 '11 at 22:42
    
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 –  Soren Aug 11 '11 at 22:49
    
I updated my answer. Basically Ctrl C did not terminate a script, that I think should be terminated on doing Ctrl C. –  abc Aug 11 '11 at 23:01
    
Does stty -a output contain intr=^C? How do you run the script? –  Stéphane Gimenez Aug 11 '11 at 23:04
1  
Please do not cross-post questions. Choose the site you want to ask on, and tailor it to that site. –  nhinkle Aug 11 '11 at 23:09
show 6 more comments

4 Answers 4

up vote 3 down vote accepted

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
share|improve this answer
    
This did not help. stty -a shows "intr = ^C" ( without the quotes) –  abc Aug 11 '11 at 21:51
    
Do I have to type the ^ character or press the Ctrl key? –  abc Aug 11 '11 at 21:54
    
you just have to press the Ctrl key (^ is short for Ctrl-) –  Soren Aug 11 '11 at 22:47
    
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 –  Soren Aug 11 '11 at 22:49
    
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. –  abc Aug 11 '11 at 23:32
show 1 more comment

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.

share|improve this answer
add comment

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.

share|improve this answer
    
Ctrl C on sleep 10 does not work either. –  abc Aug 12 '11 at 3:02
2  
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. –  abc Aug 12 '11 at 3:24
add comment

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 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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.