windows 使用python获取进程ID

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3853703/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 15:21:37  来源:igfitidea点击:

Get process ID with python

pythonwindowswinapi

提问by AKM

How to get the current process id with python on windows?

如何在windows上使用python获取当前进程ID?

there are this function os.geteuid() but its only works with linux/unix could someone tell what it the pythonic way to get the current process id on windows.

有这个函数 os.geteuid() 但它只适用于 linux/unix 谁能告诉它在 Windows 上获取当前进程 id 的 pythonic 方式。

回答by RichieHindle

Do you really want the process ID? Then the answer is this:

你真的想要进程ID吗?那么答案是这样的:

>>> import os
>>> os.getpid()
5328

on either Windows or Unix (documentation of os.getpid).

在 Windows 或 Unix 上(文档os.getpid)。

os.geteuid()doesn't get the process ID, which makes me wonder whether you're really asking a different question...?

os.geteuid()没有得到进程 ID,这让我想知道你是否真的在问一个不同的问题......?