in windows you can use taskkill inside subprocess.call :
subprocess.call(["taskkill","/K","/IM","firefox.exe"])
A clean / more portable solution with psutil (well, for Linux you need to drop the .exe part or use .startwith("firefox") :
import psutil,os for pid in (process.pid for process in psutil.process_iter() if process.name()=="firefox.exe"): os.kill(pid)
which will kill all processes named firefox.exe
EDIT: os.kill(pid) is "redundant." process has a kill() method, therefore:
for process in (process for process in psutil.process_iter() if process.name()=="firefox.exe"): process.kill()
Jean-FranΓ§ois Fabre
source share