0

I could issue command

In [41]: !killall "Expert PDF"

to kill a process, or encapsulate it in subprocess

subprocess.run("killall 'Expert PDF'",shell=True)

I wonder how could accomplish such a task with pure python code?

glibdud
  • 7,550
  • 4
  • 27
  • 37
AbstProcDo
  • 19,953
  • 19
  • 81
  • 138
  • 1
    Do any of these answers help? https://stackoverflow.com/q/2940858/866021 – Adil B May 30 '18 at 16:50
  • If you know command to kill the processes then you should try **os.system("")**. – hygull May 30 '18 at 17:01
  • What's your OS? – pushkin May 30 '18 at 17:02
  • 1
    Possible duplicate of [Is it possible to kill a process on Windows from within Python?](https://stackoverflow.com/questions/6278847/is-it-possible-to-kill-a-process-on-windows-from-within-python) – pushkin May 30 '18 at 17:02
  • 2
    *"Pure Python?"* No. Only the operating system can kill a process. Python must ask the operating system to kill the process using something like `subprocess`, `os.kill` or `os.system`. – Aaron May 30 '18 at 17:20
  • 1
    @Aaron Python also has to ask the OS to create/open files, make network connections, write text to the terminal, etc. By your logic, "pure Python" can hardly do anything by itself. – Barmar May 30 '18 at 18:11
  • 1
    Possible duplicate of [Kill process by name?](https://stackoverflow.com/questions/2940858/kill-process-by-name) – Adil B May 30 '18 at 18:20

0 Answers0