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.

Related Posts:

  • Pkill - an Easier Linux Kill Command
  • Linux Trademark Issues
  • To Many Linux Distros?
  • The ignorant article by Frank Hayes!
  • Open Media Commons
  • Will the MS-Novell deal tear Linux community appart?
  • Your perfect Linux Distro?
  • Katapult: Launchy/Quicksilver for Linux
  • Text Dumping PDF files
  • Flash Player 9 on Linux

  • 19 Responses to “How To Kill Stuff On Linux”

    1. Gravatar k00pa FINLAND Says: Reply to this comment

      Awesome article! Thanks!

      Posted using Konqueror Konqueror 3.5 on Kubuntu Linux
    2. Gravatar vacri AUSTRALIA Says: Reply to this comment

      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.

      Posted using Debian IceWeasel 2.0.0.6 on Debian GNU/Linux Debian GNU/Linux
    3. Gravatar Luke Maciak UNITED STATES Says: Reply to this comment

      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.

      vacri said:

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

      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. )

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.6 on Ubuntu Linux Ubuntu Linux
    4. Gravatar vacri AUSTRALIA Says: Reply to this comment

      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…

      Posted using Debian IceWeasel 2.0.0.6 on Debian GNU/Linux Debian GNU/Linux
    5. Gravatar Luke Maciak UNITED STATES Says: Reply to this comment

      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.

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.6 on Ubuntu Linux Ubuntu Linux
    6. Gravatar vacri AUSTRALIA Says: Reply to this comment

      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 )

      Posted using Debian IceWeasel 2.0.0.6 on Debian GNU/Linux Debian GNU/Linux
    7. Gravatar Luke Maciak UNITED STATES Says: Reply to this comment

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

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.7 on Windows Windows XP
    8. Gravatar vacri AUSTRALIA Says: Reply to this comment

      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.

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.7 on Windows Windows XP
    9. Gravatar Luke Maciak UNITED STATES Says: Reply to this comment

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

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.7 on Windows Windows XP
    10. Gravatar cornel panceac ROMANIA Says: Reply to this comment

      BUSIER on reverse

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.5 on Fedora Linux Fedora Linux
    11. Gravatar Carl-Johan Kjellander SWEDEN Says: Reply to this comment

      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.

      Posted using Mozilla Firefox Mozilla Firefox 1.5.0.12 on Fedora Linux Fedora Linux
    12. Gravatar Luke Maciak UNITED STATES Says: Reply to this comment

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

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

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.6 on Ubuntu Linux Ubuntu Linux
    13. Gravatar Jeff Says: Reply to this comment

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

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.7 on Windows Windows XP
    14. Gravatar polarizer GERMANY Says: Reply to this comment

      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

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.6 on Ubuntu Linux Ubuntu Linux
    15. Gravatar Linux Notfall Shutdown « LoBlog Says: Reply to this comment

      […] via terminally incoherent Kategorien […]

      Posted using WordPress WordPress MU
    16. Gravatar Carson UNITED STATES Says: Reply to this comment

      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).

      Posted using Opera Opera 9.24 on Windows Windows XP
    17. Gravatar 23rd World » Kill is Your Friend Says: Reply to this comment

      […] Worked like a charm. Another hint for you fellow newbs…maybe reading an Apache admin book would actually SAVE you time, eh? All I needed to do to enable my dern rewrite was to change AllowOverride None to AllowOverride all in my sites-enabled config. Hmmm….I bet a quick doc on configuring sites in Apache2 would have saved me all that. But then I wouldn’t have ever found out how to kill stuff on linux…so then again, maybe it was all worth it. […]

      Posted using WordPress WordPress 2.3.2
    18. Gravatar Starhawk Says: Reply to this comment

      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.

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.11 on Ubuntu Linux Ubuntu Linux
    19. Gravatar Luke Maciak UNITED STATES Says: Reply to this comment

      Bad language? I never use bad language! ) lol

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.14 on Windows Windows XP

    Leave a Reply

    XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <pre lang=""> <em> <i> <strike> <strong>

    [Quote selected]