How to kill all process of one user?
When I make ps aux
I obtain a list of process with several users, and I want to kill all process of user name1
, for example. What's a command to do that in Ubuntu?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityIn this case, it's pretty simple, you can use killall
to kill, or send any other signal, to a bunch of processes at once. One of the "filtering" options is the owner: killall --user name1
killall
in e.g Solaris Unix kills all running processes it can! See: en.wikipedia.org/wiki/Killall
Mar 27, 2012 at 18:25
Adding another option because nobody has mentioned it, and I don't like killall
(using it on solaris can cause disaster).
pkill
is more portable
pkill -u username
killall
on a CentOS machine, but I've always seen pkill
on the machines I've used. This is probably the more portable answer.
Jul 26, 2021 at 23:07
Install slay
:
aptitude install slay
Then issue slay some-user
.
Be aware that if you kill off stuff for users you don't know the purpose for, you may render your machine unusable (until you restart).
If you really don't want to install slay:
ps -e -o user,pid | grep '^some-user ' | awk '{ print $2 }' | xargs kill
(wait a bit)
ps -e -o user,pid | grep '^some-user ' | awk '{ print $2 }' | xargs kill -9
awk
can grep something itself. No need to do grep smth | awk
, cause you can use just awk '/smth/{...}'
instead.
killuser () { ps faux| awk -v user=$1 '$1==user{ system("kill -9 " $2) }' ;};
Mar 28, 2017 at 16:20
Identify the user, then killall -user <username>
They will have a bash (or similar) process associated with their login session killing that will kill their session.
To get a potentially better overview of what a user is doing - try pstree <username>
According to man kill
:
kill -9 -1
Kill all processes you can kill.
To apply it to a different user:
su -l username kill -9 -1
sudo service the-service-name stop
. Killing processes may left corrupted files, databases, etc.