Any system administrator worth his or her salt knows
pkill. But for a quick, clean kill, there's
If you must kill all processes by a user--whether it's because the user is running malicious processes, the user is being removed from the system, or any other reason--
slay is the hands-down fastest way to do it.
Slay was originally written by Chris Ausbrooks, and it has been "heavily rewritten for Debian," according to its copyright file. I'm using it on Ubuntu Server right now. You can grab the package with
apt-get install slay.
The usage is very straightforward: Just run
slay username and
slay will send a kill signal to all processes owned by the user. Use
slay -signal if you want to send a specific signal to the processes.
Want to give the processes a chance to clean up after themselves before termination? Use the
slay will send processes a TERM signal, then KILL if they haven't terminated after 10 seconds.
Big Word of Caution
Here's the big caveat with
slay: By default, it's in "mean" mode. What does that, er, mean? The default is to kill the user's processes if he isn't logged in as root. So if you happen to be logged in as your normal user, and think "hey, I'm going to kill all of lameuser's processes" be sure to switch to root first. Otherwise, the default mode for slay is to turn the tables and kill your processes. You're going to get a quick note saying "Illegal operation" and then
slay will kill your processes. This also means you'll be logged out immediately, too. And if you were trying to fight a fire on a slow-running system that has trouble handling logins, that could be a bad thing indeed. It's a good lesson for users who shouldn't be mucking with
If you don't like the default "mean" option, you can tell
slay to play nice. You'll have to edit
/etc/slay_mode, and change mean to nice. If the file doesn't exist, create it. It only needs to have one word (nice).
This isn't the world's most ground-breaking utility, but it's handy in a pinch. You can quickly and effectively kill processes that are out of control--including your own if you leave mean mode on.
Hat tip to Axel Beckert for reminding me about
slay. I'd known about the utility for some time, but completely forgot about it.
Joe 'Zonker' Brockmeier is a freelance writer and editor with more than 10 years covering IT. Formerly the openSUSE Community Manager for Novell, Brockmeier has written for Linux Magazine, Sys Admin, Linux Pro Magazine, IBM developerWorks, Linux.com, CIO.com, Linux Weekly News, ZDNet, and many other publications. You can reach Zonker at firstname.lastname@example.org and follow him on Twitter.