是“系统"吗?和“系统空闲进程"Windows 上的 PID 不变? [英] Are the "System" and "System Idle Process" PIDs constant on Windows?
问题描述
在我看过的几个 Windows XP 系统上,系统空闲进程"的 PID 始终为 0,而系统"进程的 PID 始终为 4.在枚举进程的 Windows 程序中,是否安全通过这些 PID 识别这些过程,或者它们在某些情况下会有所不同吗?
On a couple of windows XP systems I've looked at, the "System Idle Process" always has PID 0, and the "System" process always has PID 4. In a Windows program which enumerates processes, is it safe to recognise these processes by these PIDs, or can they be different in some circumstances?
推荐答案
我的生产代码假定这些 PID 是静态的,并且它适用于 XP、Vista 和 Win 7.不过不确定它是否是官方支持的方法!
I have production code which assumes these PIDs are static, and it works on XP, Vista and Win 7. Not sure if it's the officially supported method though!
另一种解决问题的方法:
Another couple of ways of approaching the problem:
- 按升序对活动 PID 列表进行排序 - 系统空闲和系统进程应该是前两个.
- 检查给定进程的父 PID - 系统空闲和系统进程的父 PID 均为 0.
这篇关于是“系统"吗?和“系统空闲进程"Windows 上的 PID 不变?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!