Are the “System” and “System Idle Process” PIDs constant on Windows?

强颜欢笑 提交于 2021-02-19 04:11:36

问题


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?


回答1:


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:

  1. Sort the list of active PIDs in ascending order - the System Idle and System processes should be the first two.
  2. Check the parent PID of a given process - the System Idle and System processes both have parent PID of 0.



回答2:


I've never seen them gaining any other PID, and I've seen many Task Managers in my tech-support days. Seems pretty constant to me. Is that guaranteed to remain in all circumstances? I'm really not sure.



来源:https://stackoverflow.com/questions/2643902/are-the-system-and-system-idle-process-pids-constant-on-windows

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!