My requirement is to kill a process. I have the process name. Below is my code:
def kill_process(name):
os.system(f"TASKKILL /F /IM {name}")
It works for Windows but not for Mac. My requirement is that it should work for both the OS. Is there a way to make the above code OS independent or how can I code it for Mac?
Any help is appreciated. Thank you.
Regards, Rushikesh Kadam.
pgrep
andpkill
are more specialized commands dealing with this than parsingps ax
and the OP specifically requested a platform-agnostic solution while this is Linux/macOS. – Girish