11

Ok, I don't know why, but I've seen this question been asked many times, but none of the answers seem to be helpful, yet the problem is quite obvious, because I verified it on several computers. Ctrl+C does NOT kill a running program in terminal (Ubuntu v10) even though it's supposed to. I wonder if anyone can actually point a solution that actually works.

So far I've tried Ctrl+\, Ctrl+SysRq+K, and much more - nothing works!

The only thing that did work, sort of, is Ctrl+Z, but it doesn't actually kill/exit the program, but simply puts it in a background and then you still have to do kill %1 to actually kill it.

Thanks!

7
  • I'm pretty sure it will kill most terminal programs; of course, it won't kill the ones that fork a new process, then return the prompt immediately. Some programs may catch this interrupt and handle it however they want, or even ignore it. It may depend a lot on whether the program is designed to be run in a terminal or from a GUI. Jun 14, 2012 at 2:40
  • I've tried many programs and none of them quit. Can you point an example program so I can verify it again?
    – techexpert
    Jun 14, 2012 at 2:41
  • Well, the one I use a lot is ping, because by default, it runs continuously. Also, the find command, or most any other bash command. Even gedit seems to work for me. I'm using 11.10, but I don't think it has changed. Are you using 10.04? I have an old 10.04 system I can test - just did, it also acts the same. Jun 14, 2012 at 2:52
  • I just tried the 'ping' and to my surprise it actually worked! I am pretty sure I've used it many times before, but I guess I am so used to 'Ctrl+Z' these days that I probably was doing just that :). It's pitty that most of the other programs I use don't obey Ctrl+C, because Ctrl+Z is begining to drive me nuts!
    – techexpert
    Jun 14, 2012 at 2:57
  • 1
    I think it should be OK to Ctrl+C, because it's not exactly a kill or Ctrl+K (which also doesn't work in those programs, btw), so the program should still be able to clean up after itself, but most programs these days choose to ignore it for some reason and this is just plain wrong and makes the command line less usable, IMO
    – techexpert
    Jun 14, 2012 at 3:05

5 Answers 5

7

Note: Answer andded after comments...

I'm pretty sure it will kill most terminal programs; of course, it won't kill the ones that fork a new process, then return the prompt immediately.

Some programs may catch this interrupt and handle it however they want, or even ignore it. It may depend a lot on whether the program is designed to be run in a terminal or from a GUI.

A few of the programs I just tried in 10.04 and 11.10 that will end are:

ping - which runs continuously by default, so this is the only way to stop it;
find - often takes a long time, so it's useful to be able to end it.
gedit
0
7

Actually, many programs will not stop on Ctrl+C because all it does is create an exception in currently running thread. Multithread programs as well as programs with "In case of any exception, go on forward." sort of instructions will continue. The proper case of actions will be either one of:

  1. Use Ctrl + Break key combo.
  2. Press Ctrl + Z. This will not stop program but will return you the command prompt. Then, do ps -ax | grep *%program_name%*. Find the line corresponding to the one yopu want to stop. The first integer in line will be program ID. Do kill -9 %id% to finally stop it.
  3. If program also eats a lot of resources, you can use top command in a separate terminal to see the ID faster.
3

I have faced this problem with one of my user having 10.04. The same issue has been discussed here CTRL+C no longer works in terminal

You can however terminate command using CTRL+SHIFT+C

It seems like copy-to-clipboard and terminate commands switched their keyboard shortcuts.

3
  • I did read this a while ago too and I have tried to disable the keyboard shortcuts for Ctrl+SHIFT+C, but it didn't make any difference for those programs that ignore Ctrl+C
    – techexpert
    Jun 14, 2012 at 3:45
  • programs like vim does not accept CTRL+C to quit/terminate itself. Jun 14, 2012 at 3:51
  • Yes, I noticed, which is why I asked the question in the first place
    – techexpert
    Jun 14, 2012 at 3:58
0

If you know the program's name, you can use pkill in another terminal. For example, if the program's name is mutt:

pkill mutt

will terminate the mutt program who wouldn't respond to CTRL + C

-1

First: top (See the PID number of the program that you want to kill its run.)

Second: kill PID

1
  • 1
    Welcome to Ask Ubuntu! top usually shows about 16 processes, which is far fewer than the total number usually running. So you might want to expand this answer with information about how to change the way top sorts processes, or otherwise how to find processes in top, and/or an alternative way to find and kill a process for when it doesn't appear. Processes one wishes to kill aren't limited to those using the most CPU (which are usually the ones shown--by default--by top). Oct 20, 2014 at 16:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .