UGTS Document #27 - Last Modified: 8/29/2015 3:23 PM
Windows Process ID Values
Process identification in Windows (or almost any OS, for that matter) can be trickier than it seems at first. This is because Process ID (PID) values can and do get re-used by Windows eventually. If all you use to uniquely identify a process is the PID, then you might get a false positive match if your PID value is extremely old and another process has since reused the PID value. This can be disastrous if you are using that PID value to search for and wait for process completion, and/or shut down the process.
Furthermore, PID values in Windows NT and higher are usually multiples of 4 not larger than 32764 (2^15-4), and so if processes are launched and terminated quickly, you might start to re-use PID values very soon.
The recommended way to be sure you are referring to the correct process is to store both the PID and the universal time that the process was started with precision at least to the minute and preferrably to the second. To get the time when the process was created, use the Windows API function GetProcessTimes, or by getting a Diagnostics.Process object in .NET and looking at the StartTime. By comparing against a (PID, StartTime) pair, there is very little chance of matching to the wrong process by mistake.