views:

1008

answers:

4

I'm developing my application (on Linux) and sadly it sometimes hangs. I can use Ctrl+C to send sigint, but my program is ignoring sigint because it's too far gone. So I have to do the process-killing-dance:

Ctrl+Z
$ ps aux | grep process_name
$ kill -9 pid

Is there a way to configure bash to send the kill signal to the current process when I press - say - Ctrl+Shift+C?

+1  A: 

Given that there's no bound key for SIGKILL, what you can do is to create an alias to save some typing, if SIGQUIT doesn't cut it for you. First, the

Ctrl+Z
$ ps aux | grep process_name
$ kill -9 pid

dance can be summarized (if there's only one instance of the process that you want to kill) as

Ctrl+Z
$ pkill -9 process_name

if your use case always goes to suspend then kill, you can create an alias to kill the last process ran like

$alias pks="pkill -9 !!:0"

Add that alias in your ~/.bash_profile.

Vinko Vrsalovic
Instead of this you could use the kill %which kills the last job
flolo
That doesn't work everywhere, flolo
Vinko Vrsalovic
On linux, killall process_name will kill all processes with that name. Caution: killall on Solaris and other unixes kills all the processes.
ataylor
+2  A: 

I don't think there is any key you can use to send a SIGKILL.

Will SIGQUIT do instead? If you are not catching that, the default is to core dump the process. By default this is ^\. You can see this by running:

$ stty -a

in a terminal. It should say:

quit = ^\
camh
How does this work? If I'm writing a new terminal application should I know about this or is it handled at a lower level?
Vinko Vrsalovic
It is handled at the tty level in the kernel. When it sees the quit key, it sends a SIGQUIT to the foreground process on that terminal. You can catch SIGQUIT if you want to stop it, but core dumps on demand are quite useful.
camh
+2  A: 

You can send a SIGQUIT signal to the current foreground process by pressing ^\ (by default, you can run stty -a to see the current value for quit.)

You can also kill the last backgrounded process from the shell by running

$ kill %%
Hasturkun
+1  A: 

My question to you would be: why is your application not handling SIGINT? Have you defined a handler for SIGINT to set a flag so that any loops can check the flag and break if it's set, or are you spinning in a system call?

converter42