Wednesday, November 12, 2008

WinAPI OpenProcess returns details for killed processes

I have just finished writing a program that involves a dispatch program that starts and manages sub programs. The loop was using OpenProcess to find if the process was still alive. The OpenProcess function returns a handle. The handle is supposed to be zero if the process doesn't exist. However, I found that after the process died, it still returned a valid handle (and many of the functions using the handle returned valid values).

To find out if the process is alive or not I finally found that using the function

ret = GetExitCodeProcess( handle, &ExitCode );

works. It returns an exit code of 259 if the process has not failed.
Post a Comment