C++, How to determine if a Windows Process is running?


Question

This is concerning Windows XP processes.

I have a process running, let's call it Process1. Process1 creates a new process, Process2, and saves its id.

Now, at some point Process1 wants Process2 to do something, so it first needs to make sure that Process2 is still alive and that the user has not not killed it.

How can I check that this process is still running? Since I created it, I have the Process ID, I would think there is some library function along the lines of IsProcessIDValid( id ) but I can't find it on MSDN

1
56
8/1/2013 8:04:40 PM

You can use GetExitCodeProcess. It will return STILL_ACTIVE (259) if the process is still running (or if it happened to exit with that exit code :( ).

67
3/20/2014 8:58:27 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon