Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

When using terminal sometimes you need to break the program. Sometimes you press Ctrl-c sometimes Ctrl-x and sometimes Ctrl-z

In some circumstances, it might simply be closing a quote or pressing enter a few times there are even instances when Ctrl-d will work.

So when I get stuck, like an idiot, I start mashing those keys like an idiot in the hope that the process will quit. In 95% of the cases it works and when I get desperate I just close the terminal and that works 100% of the time. I'm sure there is a logical reason for the various states due to the program being in a particular state but all I want to do is just break the application and return to the bash prompt.

Is there a super key that will break the process without having to mash these 4 magic keys in the hope that the application will terminate?

share|improve this question
add comment

1 Answer 1

up vote 3 down vote accepted

The super key is closing the terminal. :-) That, or the power button on your computer.

Each of the key combinations Ctrl+c, Ctrl+x, Ctrl+z, and Ctrl+d does a different thing.

  • Ctrl+c : generates an interrupt signal.

  • Ctrl+x : I'm not sure what this does.

  • Ctrl+z : suspend the process, allowing it to be resumed at a later point.

  • Ctrl+d : sends an end-of-file signal.

Each process is at liberty to interpret these signals as they see fit. Hence, there is some heterogeneity in the response.

A more generic way to terminate a process would be to kill it with a SIGKILL signal, which (I think) is the same as closing the terminal window. It's better to attempt Ctrl+d and Ctrl+c first though, because these are signals that the process can anticipate, allowing it to end in a predictable and safer way.

share|improve this answer
    
ctr-z suspend, didnt know that, how do you resume? –  Meer Borg Apr 4 '13 at 4:50
    
If there's a single process, then just type fg. You can also resume it in the background with bg. There's quite a lot you can do with this, running multiple jobs in a single terminal. Try googling "bash jobs" or similar. –  Sparhawk Apr 4 '13 at 4:54
    
Thanks, i normally use screen command for that, always wanted to know why when exiting terminal it said there were running jobs, now I know, pressed ctr-z wrongly sending it to background instead of terminating –  Meer Borg Apr 4 '13 at 5:06
    
Closing the terminal window sends SIGHUP, I believe. You should only send SIGKILL as a last resort, since it forces a program to quit without having a chance to clean up after itself. Better to send SIGTERM or even a manual SIGHUP. –  Scott Severance Apr 4 '13 at 8:49
    
@ScottSeverance Yeah, I didn't really go into SIGTERM, but I suspect that SIGINT (Ctrl+c) or EOF (Ctrl+d) are even safer? But yes, I agree that SIGTERM is better than SIGKILL. –  Sparhawk Apr 4 '13 at 10:38
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.