How To Kill Stuff On Linux

You are happily working on your linux box when all of a sudden something freezes and becomes unresponsive. What do you do? Let’s talk about killing today!

Killing Stuff On Linux
img © Rossy ℗∑ñℊ⊍ïñ found @ evilpenguins.tribe.net

Everything really depends on situation. If it’s just a single application that decided to stop responding you can simply kill it. Now, you may think that killing is a bit harsh punishment for not talking to you – and it is. Best practice is to wait a little bit, and the app may un-freeze itself eventually. Chances are that some blocking process seized up the focus, and rendered GUI unusable for a little while. Then again, applications sometimes just freeze or get themselves into a runaway loop. And then there is not much you can do but send them SIGTERM or SIGKILL signal using kill or killall. The former takes the PID of the process as an argument, while the latter takes a name of the binnary and additionally tries to kill the whole process tree which is usually (but not always) a good idea. Note that both commands send SIGTERM by default which is essentially equivalent to nicey asking them to drop dead. If you use -9 you no longer ask – you shiv them in the heart with a rusty spork and watch them bleed to death on your new carpet. And by that I mean data loss, and other unexpected side effects so use it carefully. RTFM for all the other fun signals you can send to your processes.

But how do I kill something if I don’t even know whats it’s pid or the name of the binary?

Good question, voice in my head. You always bring up these interesting things. There are three ways to deal with this problem. First one is to STFU, stop being such a luser and use ps, and top to figure out which application is acting up and then -9 it like a man. But if you can’t handle that, there are two other remaining alternatives for the whussies: pkill, and xkill.

I mentioned pkill before, so I’m not going to repeat myself. All you need to know is that pkill is a smart fellow. He went to ninja school and is sneaky enough to figure out that when you tell it to kill firefox, you really mean firefox-bin. By that logic Kill and killall are kinda like mob hitmen – effective, but dumb as bricks. You have to tell them exactly who to hit, and how.

Xkill is kill’s graphically inclined cousin who specializes in killing windowed applications. When you call him, he appears as a stylish (or tacky, depending on your taste) black skull and bones cursor. Kinda like an inverse Jolly Roger. If pkill is a ninja, then xkill is a pirate of the bunch. Think Jack Sparrow – can be quite destructive if aimed well, but tends to blow shit up if you underestimate him (ie. click in the wrong place). Point him at your frozen window, hit LMB and he will do the rest. Note that if you change your mind you can cancel it by clicking anywhere with RMB.

What if my whole X seems to be locked up?

Easy – swith to a TTY using Ctrl+Alt+F1 (or any function key from F2 to F6 for that matter)! Then use top/htop or whatever strokes your fancy to figure out which app is hugging all the CPU and eating all the memory. Kill it and chances are that all the other software will be given a breath of fresh air and will resume normal function. You can switch back to X with Ctrl+Alt+F7.

If that doesn’t work, and you don’t mind loosing some data, you can give X the good old 3 finger salute. And no, it’s not that one. The old Ctrl+Alt+Del salute remains a fond memory of Win-DOS 95 users whose machines had those awesome reset buttons on the case, that helped them to recover from frequent BSOD’s. Reset buttons are a thing of the past, and so is the Ctrl+Alt+Del which acts as a key shortcut to bring up task management console, or logout dialog on most modern systems. Let’s face it – pressing this key combination no longer feels like saying “Fuck You OS, eat shit and DIEEE!”.

The 3 finger salute I’m talking about is Ctrl+Alt+Backspace – and it’s the key combination that will kill your current X session. And it will give you as much gratification, and therapeutic frustration relief as Ctrl+Alt+Del in the good old times but without actually hosing the filesystem or making the system unstable. Think of it as a forced logout combined with a restart of the X server. 98% of the time this will do the trick and let you resume work quickly and easily.

What if my system is frozen solid?

There is still a way to restart it gracefully using the magic SysRq key combo. Simply hit Alt+PrintScrn (which is how you get SysRq key) and then type in R E I S U B with… Your nose… Or other part of your anatomy. This will trigger a nice reboot that will not corrupt any of your data, destroy the file system or wreck any other crazy damage. In fact each of these keys issues a special SysRq command:

R – switch the keyboard mode
E – send all processes the SIGTERM singal
I – sends all processes the SIGKILL signal
S – Sync filesystem
U – Unmount all devices
B – Reboot immediately

Theoretically you could just do SysRq+B to do an old school, Win 95 style Alt+Ctrl+Del reboot, but it’s just as bad as hitting that power button. Your best bet is to run the whole sequence to ensure that the system shuts down in the way it would normally shut down when you issue a reboot command.

And it’s almost guaranteed to work even on a completely locked up system. That is, if it’s enabled on your system. If you are not sure, do a really quick test right now:

cat /proc/sys/kernel/sysrq

If you see a 1, you are in good shape. If you see a zero, you can enable the SysRq keys by doing:

sudo echo 1 > /proc/sys/kernel/sysrq

Better do it now before you somehow hose your system and need to use it. It’s kinda hard to issue commands when nothing responds to you.

How the hell do you expect me to remember this REISUB thing?

Mnemonics my friend. That’s how you do it. The popular one circulating out there is Rising Elephants Is So Utterly Boring. If you are more of a visual person, I have another one for you. Observe:

Rei AyanamiSubway Sub

Get it? It’s REI Ayanami from Neon Genesis Evangelion and a Subway SUB. It’s easier to remember if you are a fan of the show. Just think about Rei eating a sub and you are good to go. :)

So there you go – plenty of ways to kill, maim and slaughter your applications in many ways. And best of all – most of these are relatively safe, and won’t break shit. At least for the most part. Remember kids – kill responsibly.

[tags]kill, killall, pkill, xkill, reisub, sysrq, rei ayanami, subway, killing, linux, unix, process[/tags]

This entry was posted in sysadmin notes and tagged , , , . Bookmark the permalink.



21 Responses to How To Kill Stuff On Linux

  1. k00pa FINLAND Konqueror Ubuntu Linux says:

    Awesome article! Thanks!

    Reply  |  Quote
  2. vacri AUSTRALIA Mozilla Firefox Debian GNU/Linux says:

    Great article, never knew about this. Did a little digging, and the wikipedia page mentions an easier way to complete the task for some systems. Also, it mentions that this function needs a particular flag to be not turned off when compiling a kernal.

    An alternative to issuing the REISUB/RSEIUB keystrokes is to just press Alt + SysRq + R, followed by Ctrl + Alt + Del. This is the equivalent of issuing a shutdown now command at a root console; it does take a short while for the system to shut down after the Ctrl + Alt + Del keystroke. However, not all Linux systems support this easier method.

    Hrm… my next port of call is going to be “Stopping fonts from sucking in Debian”, I think.

    Reply  |  Quote
  3. Luke Maciak UNITED STATES Mozilla Firefox Ubuntu Linux says:

    I can confirm that REISUB works on Dapper out of the box. So I guess it’s a fair assumption that most of the Ubuntu line kernels are compiled with that option.

    [quote comment=”6459″]Hrm… my next port of call is going to be “Stopping fonts from sucking in Debian”, I think.[/quote]

    Did you install the True Type fonts yet? The package name is msttcorefonts for both ubuntu and debian I think. They don’t really “stop fonts from sucking” but it may help to make pages that use these fonts by default to look more like they were designed to look on windows. :)

    Reply  |  Quote
  4. vacri AUSTRALIA Mozilla Firefox Debian GNU/Linux says:

    this article couldn’t have come at a better time – playing (unsuccessfully) with power management on the way home, resuming from suspension craps out both graphic and text consoles (though I do get a pointer…). sysrq reboot ftw!

    I have just installed the msttfonts package and things are better, but yeah, they’re not good. I was looking at a page that had ‘config’ with a f-i ligature and an i-g ligature, so the word looks like ‘confg’ as the i is totally lost. The new fonts have improved stuff elsewhere, but I’m still gong to have to be careful :/ Hello-o-o google…

    Reply  |  Quote
  5. Luke Maciak UNITED STATES Mozilla Firefox Ubuntu Linux says:

    Yeah, ACPI can be funky like that sometimes. I hardly ever use suspension or hibernation because it’s always a gamble. Will it, or will it not come back?

    Btw, what page were you looking at? I never really noticed that problem.

    Reply  |  Quote
  6. vacri AUSTRALIA Mozilla Firefox Debian GNU/Linux says:

    This old howto is the page with the problem, both with the regular body text and the highlighted bold text. Monospace is fine on that page. Found that page when I was poking around for howtos, and it was visually terrible before the msttfonts. In the first paragraph in section 3 there are several ‘configs’ that still exhibit problems.

    Power management will work on this lappy, I just need to find the right settings. My morning commute is two sections of public transport with a walk in-between, so it’d be good to figure out :)

    Reply  |  Quote
  7. Luke Maciak UNITED STATES Mozilla Firefox Windows says:

    Have you tried to change the default font in Ice Weasel? It should be under the Content tab.

    Reply  |  Quote
  8. vacri AUSTRALIA Mozilla Firefox Windows says:

    Yeah, I changed from defaults to the dejavu set (this was set before msttfonts), still has the same problems. No matter, I’ll poke around from time to time when the mood strikes. It’s amazing how invisible fonts are until they’re broken.

    Reply  |  Quote
  9. Luke Maciak UNITED STATES Mozilla Firefox Windows says:

    Weird, I never had any issues with fonts on Ubuntu. Have you tried setting it to like Times New Roman or something?

    Reply  |  Quote
  10. cornel panceac ROMANIA Mozilla Firefox Fedora Linux says:

    BUSIER on reverse

    Reply  |  Quote
  11. Carl-Johan Kjellander SWEDEN Mozilla Firefox Fedora Linux says:

    Alt-SysRq-K is often forgotten combination. It’s the Sceure Access Key and it will kill everything on the current terminal and give you a fresh one.

    So if Xorg goes into an infinite loop and refuses to take care of your Ctrl-Alt-Backspace, the Alt-SysRq-K will kill X for you instead.

    Reply  |  Quote
  12. Luke Maciak UNITED STATES Mozilla Firefox Ubuntu Linux says:

    @cornel panceac – yeah, that too. I still like my visual example better though. :)

    @Carl-Johan Kjellander – I forgot about that one! Thanks!

    Reply  |  Quote
  13. Jeff UNITED STATES Mozilla Firefox Windows says:

    Funny, I’ve always remembered it as BUSIER backwards.

    Reply  |  Quote
  14. polarizer GERMANY Mozilla Firefox Ubuntu Linux says:

    Yes – it works. For some reason i had to do it today while i were in a console during the install process of debian/ubuntu. For my view it was remarkable that here each keystroke was responded by the system with a instant log about what happens. Normally i had at most a blinking hdd LED while typing the S of REISUB for the sync.

    my 2 cents – the polarizer

    Reply  |  Quote
  15. Pingback: Linux Notfall Shutdown « LoBlog UNITED STATES WordPress

  16. Carson UNITED STATES Opera Windows says:

    Thanks especially for the SysRq info. I’ve used Linux since 1998, but I’ve never known those key combos (guess I never needed them).

    Reply  |  Quote
  17. Pingback: 23rd World » Kill is Your Friend UNITED STATES WordPress

  18. Starhawk UNITED STATES Mozilla Firefox Ubuntu Linux says:

    This is a great article luke I been using it on the Ubuntu forums some tho technically ya not supposed to link to articles with “bad language” in it. I think at least, no one has complained lol.

    Reply  |  Quote
  19. Luke Maciak UNITED STATES Mozilla Firefox Windows Terminalist says:

    Bad language? I never use bad language! ;) lol

    Reply  |  Quote
  20. In all this time I never heard of REISUB. Thanks for the info! My laptop actually has a SysRq key on it, so it’s ready to go. Maybe that’s how my cat manages to do amazing, annoying things to my laptop when running across the keyboard.

    Reply  |  Quote
  21. Luke Maciak UNITED STATES Mozilla Firefox Windows Terminalist says:

    @Chris Wellons: Actually, it has been scientifically proven that most cats have reflexive and instinctive linux skills. Sadly most of them can’t read so they just issue random CLI commands or key stroke combination when faced with a linux computer. If you are lucky, they will upgrade and patch your kernel or get our Wifi card to work. If you are unlucky they will repartition your drive or delete the root folder.

    Reply  |  Quote

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>