Detect If Process Is Still Running (Solved)

Started by
4 comments, last by Sneftel 18 years, 4 months ago
Hello, In my code I am storing a number of process IDs. I would like to be able to find out when one of these processes close. The only way I can think to do this is to perform some sort of check on each ID once per second or so. My question is, how can I quickly find out if a process is still running given only its process ID? I know about using WaitForSingleObject to check if a process is running given a HANDLE, but I don't have the HANDLE available--just the ID. If it matters, I'm getting the process IDs from HWNDs with GetWindowThreadProcessId. Thank You! Jon Woyame [Edited by - JonWoyame on November 29, 2005 1:09:41 PM]
Advertisement
Use OpenProcess to get a handle from a process ID>
Would it be better to call OpenProcess to get the handle when I first retrieve the ID, and then just leave the handle open until the process ends, than to call OpenProcess on the ID every time I want to check that it is running?

The documentation doesn't give a whole lot of info on what OpenProcess actually does, besides the fact that it returns a handle. I didn't want to use a handle if creating it requires a bunch of extra resources to be allocated.


Thanks again.
Yeah, create the handle once and keep it around. A process handle is really the Right Way for a process to know about another process. Process IDs are more a user-level thing.
OK, great.

Response in < 5 minutes both times. Hmm... I'm beginning to wonder if you're an autoresponse bot ;)
Syntax error. Please rephrase.

This topic is closed to new replies.

Advertisement