I want the python syntax that will give me the list of background processes running through python itself, and kill all those processes at a time. what modification should I do in my following code?
I have written this code to get all the running processes and kill the specific one by its name.
import psutil
for proc in psutil.process_iter():
try:
# Get process name & pid from process object.
processName = proc.name()
processID = proc.pid
print(processName , ' ::: ', processID)
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
pass
for proc in psutil.process_iter():
if proc.name() == "powershell.exe":
proc.kill()