winapireturn-codeopenprocess

how GetExitCodeProcess get exit code when the process is not there anymore


I first get handle to a process by using OpenProcess. Then I call GetExitCodeProcess in a loop to see if the process is running. But how does GetExitCodeProcess get exit code? Does Windows store exit code of all processes that ran in the past 30 minute or something? As soon as the application exits, any information regarding the process is wiped out from Windows. I don't know how GetExitCodeProcess can get exit code of something that no longer exists...


Solution

  • The exit code is saved in the process object, which is destroyed when the last handle is closed. So don't close that handle until you're really done!