How to kill all processes run by a user on Linux

If you are a system administrator, there are situations where you want to kill all processes belonging to a specific user, for example because the user is being removed from the system, or the user is forking malicious processes or runaway daemons, etc. It will be cumbersome to kill individual processes of the user one by one manually.

In this tutorial, I will show how to kill all running processes launched by a user at once. Here, I will demonstrate several commands that kill all processes owned by Linux user "xmodulo".

Method One

The first method is to feed kill command with a list of process IDs generated by ps command.

$ ps -ef | grep xmodulo | awk '{ print $2 }' | sudo xargs kill -9

Method Two

A more convenient way to look up processes based on user name is to use pgrep.

$ pgrep -u xmodulo | sudo xargs kill -9

Method Three

pkill can streamlines the whole process of looking up processes by user, and sending them signals. A default signal sent by pkill is SIGTERM. Using pkill, you can kill all processes by owner easily.

$ sudo pkill -u xmodulo

Method Four

killall is very similar to pkill in terms of killing processes by user name.

$ sudo killall -u xmodulo

Method Five

A command line tool whose sole purpose is to kill processes by owner name is slay. It provides "clean kill" mode, where matched processes are first sent SIGTERM signal, and those that haven't been terminated after 10 seconds are killed with SIGKILL signal. slay is available on Ubuntu or Debian. To install slay and use it:

$ sudo apt-get install slay
$ sudo slay xmodulo

Precaution: When using slay, pay particular attention to sudo or run it as root. If you by accident attempt to slay another user as non-root user, it will of course not work, and more importantly, slay will kill your own processes!

Subscribe to Xmodulo

Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.

Support Xmodulo

Did you find this tutorial helpful? Then please be generous and support Xmodulo!

The following two tabs change content below.
Dan Nanni is the founder and also a regular contributor of He is a Linux/FOSS enthusiast who loves to get his hands dirty with his Linux box. He likes to procrastinate when he is supposed to be busy and productive. When he is otherwise free, he likes to watch movies and shop for the coolest gadgets.

Leave a comment

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