Windows PID = 0 有效吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3232401/
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
windows PID = 0 valid?
提问by user156144
In Windows, is 0 valid PID for a process or is it reserved by OS? It would be nice if you can provide a link to a doc that says it is reserved or what. Thank!
在 Windows 中,0 是进程的有效 PID 还是由操作系统保留?如果您可以提供一个指向文档的链接,说明它是保留的或其他内容,那就太好了。谢谢!
采纳答案by developmentalinsanity
Open task manager - switch to the processes tab (maybe click "View", "Show columns" and enable the PID column).
打开任务管理器 - 切换到进程选项卡(也许单击“查看”、“显示列”并启用 PID 列)。
PID 0 is the System Idle Process. Since that process isn't really a process and never exits, I suspect that it is always the case.
PID 0 是系统空闲进程。由于该进程并不是真正的进程并且永远不会退出,因此我怀疑情况总是如此。
No documentation available to me, but I'm pretty certain this is always going to be the case.
我没有可用的文档,但我很确定情况总是如此。
回答by wj32
It's not stated anywhere but it comes down to how the kernel handle table works. This same object is used for both process handles and process/thread IDs. It happens that handle values all start at 0x4, and PsInitialSystemProcess is the first process to be created, so it gets a PID of 4. Idle process isn't actually a process and you can't open it. It probably doesn't have a PID for most intents and purposes but most tools consider it to be 0.
它没有在任何地方说明,但归结为内核句柄表的工作方式。同一个对象用于进程句柄和进程/线程 ID。碰巧句柄值都从 0x4 开始,并且 PsInitialSystemProcess 是要创建的第一个进程,因此它的 PID 为 4。空闲进程实际上不是一个进程,您无法打开它。对于大多数意图和目的,它可能没有 PID,但大多数工具认为它是 0。
回答by codekaizen
The PID of 0 is reserved for the Idle "psuedo-process", just like PID of 4 is reserved for the System (Windows Kernel).
0 的 PID 是为空闲的“伪进程”保留的,就像 4 的 PID 是为系统(Windows 内核)保留的一样。
I can't find any documentation on where that is specified, but querying the processes via any API (Perf Counters, WMI) will always give you the idle process for PID 0.
我找不到有关指定位置的任何文档,但是通过任何 API(Perf Counters、WMI)查询进程将始终为您提供 PID 0 的空闲进程。