>> Windows does not have a need for such a unique identifier, so it doesn’t
> create such a thing.
> Once a process is dead, it is irrelevant. (Linux doesn’t either, FWIW.)
Well, although I don’t see any need for any OS to have such a unique ID,
I immediately see the reason for doing exactly the opposite, i.e. reusing
the ID. After the main thread of a process has entered terminated state
and all outstanding references went down to zero, there is no need for any
structures that it occupies. Therefore, ythe OS is left with two options -
either to free the memory occupied by these structures so that it gets
re-purposed, or simply to re-initialize few fields of these structures and
immediately reuse them the next time new process is created. Which of them
is more reasonable???
Note that Windows has no concept of a “main thread”; in general, the main
thread can exit any time, and the process is live as long as there is any
potentially runnable thread in the process. System Services critically
depend on this behavior. Windows CE and its various evolutionary
renamings got this wrong, and when the “main thread” terminates, the
process terminates.
The process object remains “live” as long as there are outstanding handles
to it, and the process ID will not be reused until the process object is
closed. This is why it is important for a process that calls
CreateProcess to close both the process handle and thread handle when it
no longer needs them. While the address space evaporates in a puff of
greasy blue smoke, the process object remains live in the kernel until its
handle count goes to zero.
After the process object is deleted, the details of whether or not the
fields of a structure are reused or new storage is allocated falls into
the category of Undocumented Magic.
The most obvious question is “what does it have with PID and why cannot
you assign a new PID for a structure that you want to reuse”. The answer
is obvious as well - instead of dumbly assigning an ID to a process you
can use it in more meaningful way, i.e. as an index. If you do it this
way, you will be able,
given a PID, to locate its corresponding process structure right on the
spot, instead of checking the entire process table…
Anton Bassov
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer