Today I learned:

How to kill rogue background Python processes

I started a simple Python http server as a background process at the end of a Python script. That was a mistake. Since it isn’t running in an open Terminal window, it is easy to forget about and it will run until you kill the process or reboot your machine. I don’t like that.

Here is how to identify and kill background Python processes in


ps -elf | grep python

This will return something like this:

501 74440 74439     4004   0  31  0  2505592   9276 -      S        0 ??         0:00.29 python -m Simple  8:43AM
501 77045 77016     4006   0  31  0  2436888    812 -      S+       0 ttys000    0:00.00 grep python       8:57AM

The second column is the PID. Make note of which one you want to kill. Then run:

kill -9 PID

Example. Let’s say I want to kill the python -m SimpleHTTPServer process. I see that its PID is 74440. So I would run:

kill -9 74440
View more TIL posts