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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With