I'm using Python 2.6. Sometimes there become several instances of a certain process open, and that process causes some problems in itself. I want to be able to programatically detect that there are multiple instances of that process and to kill them.
For example, maybe in some cases there are 50 instances of make.exe open. I want to be able to tell that there are 20 instances open, and to kill them all. How is this accomplished?
A process can be killed by calling the Process. kill() function. The call will only terminate the target process, not child processes. The method is called on the multiprocessing.
If you're using Popen , you should be able to terminate the app using either send_signal(SIGTERM) or terminate() .
I would think you could just use taskkill and the Python os.system()
import os os.system("taskkill /im make.exe")
Note: I would just note you might have to fully qualify the taskkill path. I am using a Linux box so I can't test...
Yes,You can do it
import os os.system("taskkill /f /im Your_Process_Name.exe")
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