I need to kill a few Python processes. I can get a list of the process numbers using
pgrep python, but how can I kill them all at once instead of killing one by one?
I'm looking for something like:
pgrep python | kill process_nos
Stack Exchange network consists of 181 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.Visit Stack Exchange
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.Sign up to join this community
You can try:
pgrep python | xargs kill
pkill(as pointed out by @tink: superuser.com/a/742741)
Short and sweet, man pkill for details.
pkill pythondoes not always work, in cases where
kill PIDneither works. But
pgrep python | xargs kill -9does. Can pkill do the equivalent?
pkill -9 <...>Nov 17, 2019 at 16:44
@tink has the correct answer, but I wanted to add that you want to make sure you are using the correct format for your machine. If you are using a Linux machine,
pkill python is correct, but if you are using a Mac terminal, you will want to use
pkill Python. So the most correct answer would be this:
<process_name> is the case-sensitive name of the process to kill.
Note: I understand that the tags for this question were related to Ubuntu Linux, but I wanted to clarify this for anyone that has a different machine but had this exact question (like myself).
pkill is a bit too radical for your tastes and you prefer to select which entries of the
pgrep listing you want to kill, you can have a look at
ezkill <https://github.com/Kraymer/ezkill> that i wrote.
Simply just run -
sudo kill -9 `pgrep python`