Cross-platform way to get PIDs by process name in python

后端 未结 8 1084
后悔当初
后悔当初 2020-12-02 09:35

Several processes with the same name are running on host. What is the cross-platform way to get PIDs of those processes by name using python or jyth

8条回答
  •  爱一瞬间的悲伤
    2020-12-02 10:31

    import psutil
    
    process = filter(lambda p: p.name() == "YourProcess.exe", psutil.process_iter())
    for i in process:
      print i.name,i.pid
    

    Give all pids of "YourProcess.exe"

提交回复
热议问题