Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kill the process using its name inside linux (Python)

this works, but it kills every Python process.

pkill python

However, I cannot do:

pkill myscript.py

I have also tried killall, but with no luck either. Do I have to user regular expressions?

By the way, I want to do this in a python script with import os.

like image 481
TIMEX Avatar asked Oct 22 '09 23:10

TIMEX


1 Answers

Did you launch the Python subprocess from the same script you are killing it from? If so, see this question for details. If not, you can use pkill's -f option to search for the script name in the Python process's argument list, but you still run the risk of killing something you didn't intend to. See the man page for more info.

like image 128
Ryan Bright Avatar answered Sep 20 '22 12:09

Ryan Bright