Page 1 of 1

How to do a reliable taskkill under Linux

Posted: Fri Aug 24, 2012 10:14 pm
by Madman
I have been using Linux quite some time, and I'm very happy overall, but there is one issue that bugs me all the time.

The problem is unresponsive tasks... For example, Wine sometimes tends to freeze completely while launching some app.

And this is where things go very wrong, very fast. Alt+ctrl+del does nothing, shift+alt+ctrl+f1 does nothing, alt+tab is very spotty and usually freezes at some point. So basically system is effectively disabled by a user space application.

The best what I can do is to hold Alt+SysRq and type REISUB, which reboots the PC. But this is still awfull from my point of view.

Does anyone know if there a way to get some Windows like taskkill that gets into front even if it has to page out gigabytes of data and takes a few hours?

The system in question is Mint 13 amd64, but this can probably be tied to other distributions as well.

Re: How to do a reliable taskkill under Linux

Posted: Fri Aug 24, 2012 10:26 pm
by bthylafh
In a terminal:
ps ax | grep -i [programname]

for example:
ps ax | grep -i wine

You're looking for the first column of the returned value, say 2483 (this is the process ID). Now type
kill -term 2483
and it'll send SIGTERM to wine, which (assuming it can receive any signals) will cause Wine to terminate gracefully. If not, you can type
kill -9 2483
and it'll try to terminate Wine with prejudice, without giving it a chance to save its data files. If this /still/ doesn't work, as a last resort you can try
sudo kill -9 2483
and it'll ask you for your password. Now it'll kill Wine from a higher privilege level, which it should be unable to ignore.

Re: How to do a reliable taskkill under Linux

Posted: Fri Aug 24, 2012 10:26 pm
by ChronoReverse
The Number 9 Kill is close to invincible!

Re: How to do a reliable taskkill under Linux

Posted: Fri Aug 24, 2012 10:34 pm
by chuckula
You can also do the "pkill" version of the kill command that takes a string corresponding to all or part of the process you want killed and doesn't require you to enter the numeric process ID. One caveat of pkill is that you want to be careful about the text term you put in being too broad.

For a contrived example, I have two background services called "dbus-launch" and "dbus-daemon" running right now. If I just do "pkill dbus" then both processes would get killed, even if I only really wanted "dbus-launch" killed. A way of checking which process will be killed is to simply run the "pgrep" command before pkill and make sure that the results of pgrep only include one or more processes you want dead.

Re: How to do a reliable taskkill under Linux

Posted: Fri Aug 24, 2012 10:44 pm
by Madman
The problem is that I cannot get to the console. Alt+Ctrl+t doesn't work. Whole desktop is captured by Wine or other misbehaving program, and even shortcut to clean terminal session - alt+ctrl+shift+f1 doesn't do anything.

I know about kill or killall, but I cannot launch them :(

Re: How to do a reliable taskkill under Linux

Posted: Fri Aug 24, 2012 11:11 pm
by just brew it!
If you've got another PC on the network maybe you could start a remote terminal session via SSH and kill the process from there? I agree this is a rather non-optimal solution though. In my experience it's pretty rare that Ctrl-Alt-F1 to bring up a bare console doesn't work.

Re: How to do a reliable taskkill under Linux

Posted: Sat Aug 25, 2012 12:41 am
by PenGun
You could set it up so Alt-Ctl-Backspace drops you to the console, killing off X. My Slackware dist is always set up that way. You can also change to a console with Alt-Ctl-F1 to F6 with F7 returning you to your X session.

But if you have lost the keyboard you are pretty well toast. Hardware button time, or surf in from another machine.

Re: How to do a reliable taskkill under Linux

Posted: Sat Aug 25, 2012 2:04 am
by Zoomastigophora
PenGun wrote:
You could set it up so Alt-Ctl-Backspace drops you to the console, killing off X. My Slackware dist is always set up that way. You can also change to a console with Alt-Ctl-F1 to F6 with F7 returning you to your X session.

But if you have lost the keyboard you are pretty well toast. Hardware button time, or surf in from another machine.

This. Forever this. I don't understand how X server hasn't been replaced with something better, but I've had misbehaving programs completely eat up UI responsiveness, which prevents you from launching a console since those technically become windowed and X server is likely choking on whatever application has focus. In those situations, nuking X server completely from a command shortcut has been the saving grace from needing to reboot and losing too much work. I learned this the hard way after rolling my own Gentoo installations several times. Thankfully, Gentoo boots into a CLI by default which is usable and what it falls back to when X dies. I know some distros with a default GUI just immediately relaunch X if its killed, which I'm not a huge fan of because I've had that freeze up due to the previous X session not having exited fully.

Re: How to do a reliable taskkill under Linux

Posted: Sat Aug 25, 2012 9:37 am
by bthylafh
Re-enable ctrl-alt-backspace to kill X:
http://ihaveapc.com/2011/12/how-to-enab ... -x-server/

ctrl-alt-esc should invoke xkill, which will let you click on a program to terminate.

Re: How to do a reliable taskkill under Linux

Posted: Sat Aug 25, 2012 9:42 am
by Madman
bthylafh wrote:
Re-enable ctrl-alt-backspace to kill X:
http://ihaveapc.com/2011/12/how-to-enab ... -x-server/

Thank you! A very usefull information here. Also fixes alt+shift keyboard layout switching which I was missing :)