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

Pedro picture Pedro · Oct 19, 2009 · Viewed 122.5k times · Source

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

Answer

Dolphin picture Dolphin · Oct 19, 2009

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 :( ).