PIDs are unique in one specific moment. But what about a given interval of t
seconds? Can i rely on the unique of process ids in a specific interval of
time? How long is this interval?
example: i terminate a process with the PID 123. After the time t, i start
another process. can this process get PID 123 again?
Background:
I want to check the system in a given interval for some specific processes.
I use EnumProcesses() to get all running PIDs. But i need to call
OpenProcess() and GetProcessImageFileName() for every PID to get the exe
string.
So my idea was to get the exe strings of unknown PIDs only once, so that i
save performance. I could save the PIDs of running processes dynamically in
my application, so that i know which processes i don't have to check again.
You can't rely on any time t in which PIDs are not reused. If you
want to avoid PID reuse, you have to keep handles to the processes
open in another process for the time t.
Corinna
--
Corinna Vinschen
Cygwin Project Co-Leader
Red Hat
I disagree. If I run my daily build I regularly see in Process Explorer
the same PIDs reappearing for cl.exe within a few seconds or even
fractions of a second time.
--
Stefan
> example: i terminate a process with the PID 123. After the time t, i start
> another process. can this process get PID 123 again?
Yup.
> Background:
> I want to check the system in a given interval for some specific processes.
> I use EnumProcesses() to get all running PIDs. But i need to call
> OpenProcess() and GetProcessImageFileName() for every PID to get the exe
> string.
Look at ToolHelp:
http://msdn2.microsoft.com/en-us/library/ms686701(VS.85).aspx
This may give you what you need at lower cost.
Regards,
Roger.
"roge...@gmail.com" wrote:
> Look at ToolHelp:
>
> http://msdn2.microsoft.com/en-us/library/ms686701(VS.85).aspx
>
> This may give you what you need at lower cost.
Well, for me it's easier when i get the .exe-string directly, but are you
sure that toolhelp is faster than psapi? I don't mind to keep open handles in
my application and to check them with GetExitCodeProcess(). On a normal
system this would be the common case, because there will only be few
processes started and terminated at once.