Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kill process by name and user

Tags:

process

kill

I am trying to figure out if there is a way to kill all processes by name and user. E.g. I want to kill all the Java instances run by user myuser.

As of the moment I do:

$ pgrep -u myuser java
2185
3281
3413
3504
22534
26174
27554

which gives a list of the pid of java run by mysuer. Then I kill each pid individually. Is there a better way to do this?

Thanks in advance!

like image 333
evgeni Avatar asked Feb 25 '23 09:02

evgeni


1 Answers

Use killall(1):

killall -u myuser java

Note that you may need to do this via sudo, and you may need -9 to kill processes that swallow SIGTERM:

sudo killall -9 -u myuser java
like image 200
Oliver Charlesworth Avatar answered Mar 15 '23 19:03

Oliver Charlesworth