Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Question about process IDs (PIDs)

0 views
Skip to first unread message

ets

unread,
Apr 25, 2008, 2:11:01 AM4/25/08
to
HI,
i have some general question about PIDs because i haven't found some good
documentation.

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.

Waleri Todorov

unread,
Apr 25, 2008, 3:47:55 AM4/25/08
to
That would depend on time t :)
In therory, PID is reusable, but in practice, you'll hardly ever see a resued PID, except perhaps in a very long time with a lot of processes started/terminated. Think about PID as a counter, that may wrap.

"ets" <e...@discussions.microsoft.com> wrote in message news:3380D238-6305-46A0...@microsoft.com...

Corinna Vinschen

unread,
Apr 25, 2008, 5:21:49 AM4/25/08
to
Waleri Todorov wrote:
> That would depend on time t :) In therory, PID is reusable, but in
> practice, you'll hardly ever see a resued PID, except perhaps in a
> very long time with a lot of processes started/terminated. Think about
> PID as a counter, that may wrap.

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

Stefan Kuhr

unread,
Apr 25, 2008, 8:38:14 AM4/25/08
to
Hello Waleri,

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

roge...@gmail.com

unread,
Apr 25, 2008, 12:56:29 PM4/25/08
to
On Apr 25, 7:11 am, ets <e...@discussions.microsoft.com> wrote:
> HI,
> i have some general question about PIDs because i haven't found some good
> documentation.

> 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.

ets

unread,
Apr 28, 2008, 1:51:00 AM4/28/08
to
First, thank you all for your replies. Now the whole PID story becomes clear
for me.

"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.

0 new messages