1

Is there anyway to uniquely identify python processes running on Windows 7?

I am writing an installer that needs to kill a python process for the installation to continue, the problem is there are multiple python processes running and I need to make sure I kill the correct one!

4

1 回答 1

3

假设你知道你的程序第一次被调用的命令行,它可能是这样的:

for p in psutil.get_process_list():
  if p.cmdline[0].endswith('pythonw.exe') and p.cmdline[1] == 'myscript.py':
    print p.pid

但是,在遍历各种程序的命令行时要小心,它们有不同数量的元素并且不能可靠地解包(尽管我认为 python 3 对可变长度序列解包有一些支持)。总之,值得一试。

于 2013-09-02T17:40:31.653 回答