Re: [Dev-C++] Detecting termination of a process
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: <mr...@c2...> - 2002-02-08 13:44:43
|
> We can run programs by using CreateProcess. I get the Process' handle > from that call. And that handle I pass to GetExitCodeProcess. I then > get the exit code of the Process. If the process has not yet > terminated its termination status is STILL_ACTIVE. > > Question: If I was to run a process from my application and monitor > it(detect if it is still running), how would I do it? > > Would it be that I'll have to create loop, checking the > GetExitCodeProcess if ExitCode is STILL_ACTIVE or another value? Would > this method imply performance issues (slower system run)? or is there > another way to check if the process is still running? If you really need to know exactly when the process exits, you could set a hook to intercept the message queue of the process and look for the WM_DESTROY or WM_QUIT messages. This requires that these messages are actually used in the process, though. If it's a process without a window proc it is not a good way... If you take the hook route, it is also possible to send yourself a message when the hook DLL is detached from the process, but this is probably a bit cumbersome. If your app will be doing nothing while the other process is running, I'd just sit in a loop, waiting for the process to exit. If you are going to do other stuff concurrently, and need to know exactly when the process exits, I think maybe the hook route is the best way. If you try any operations on the process handle, they will fail if the process has terminated, so that is also a way to test if the process is still running. -=D8yvind --------------------------------- mr...@c2... @ work |