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
A:
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.
M.A. Hanin
2010-04-15 08:57:28
+2
A:
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:
- Sort the list of active PIDs in ascending order - the System Idle and System processes should be the first two.
- Check the parent PID of a given process - the System Idle and System processes both have parent PID of 0.
snowcrash09
2010-04-15 13:05:41
On Windows 2000, System is 8.
Luke
2010-04-15 14:02:08
Nice spot. Just checked and parent PID of System is still 0 on Windows 2000, so maybe parent PID method is the way to go.
snowcrash09
2010-04-16 15:15:13