Processes in Windows 2003

D

Darren Kennedy

(Apologies if posting to wrong group. Is there a Windows 2003 Server
dev group?)

When I run the OpenProcess() function on Windows 2003, I continue to
get a non-NULL handle on a process that has terminated.

HANDLE hProcess = OpenProcess(READ_CONTROL, FALSE, <ProcessId>);
while (hProcess)
{
hProcess = OpenProcess(READ_CONTROL, FALSE, <ProcessId>);
// Process terminates but I keep getting a non-NULL hProcess
}

Works as expected on Windows 2000 but not on Windows 2003 Server.

Any ideas?

Thanks
-Darren
 
J

John Phillips

OpenProcess will -=not necessarily=- return NULL even if the process has
terminated. The process object will remain valid until all handles to it
are closed (BTW, in your sample code, this will never happen as you keep
creating a new handle to the process on every iteration without ever closing
any).

What are you really trying to accomplish? Are you trying to determine
whether or not the process has exited? In that case, may I suggest either
polling via GetExitCodeProcess() or the more elegant
WaitForSingleObject(hProcess)?
 
D

Darren Kennedy

I have a test manager that needs to know when the test (exe's) have
completed.

Both your suggestions work, thank you for those.

My sample code was too abbreviated (see eom). I do call CloseHandle(). Which
is why it worked on Win2k.

Now that I have a solution, I am curious as to why 2003 Server seems to
behave differently.

Thanks again

-Darren



HANDLE hProcess = OpenProcess(READ_CONTROL, FALSE, <ProcessId>);

while (hProcess) {

CloseHandle(hProcess)

hProcess = OpenProcess(READ_CONTROL, FALSE, <ProcessId>);

// Process terminates but I keep getting a non-NULL hProcess on Windows
2003 Server

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top