The MASM Forum

General => The Campus => Topic started by: xanatose on January 03, 2014, 01:22:38 AM

Title: How does one know if a process has stopped or crash?
Post by: xanatose on January 03, 2014, 01:22:38 AM
I have two process on the same machine that communicate via a memory mapped file.

Everything seem ok, except that when one process crash, the other stays waiting forever.

Using the windows api. How does a program know if a process has stopped or crashed?
Title: Re: How does one know if a process has stopped or crash?
Post by: qWord on January 03, 2014, 02:27:48 AM
You can wait for process handles (WaitForSingle/MultipleObject (http://msdn.microsoft.com/en-us/library/windows/desktop/ms687032%28v=vs.85%29.aspx)) and evaluate the process exit code (http://msdn.microsoft.com/en-us/library/windows/desktop/ms683189%28v=vs.85%29.aspx). However, it might be smarter to bring the crashing process into an defined state using an exception handler. In case of a crash you could send an unique message (RegisterWindowMessage (http://msdn.microsoft.com/en-us/library/windows/desktop/ms644947%28v=vs.85%29.aspx)) or use the process return value (ExitProcess).
Title: Re: How does one know if a process has stopped or crash?
Post by: Farabi on January 03, 2014, 08:53:45 PM
I forget how to do it, but you can modify the stack and change the GPF message box to your own procedure, I think I posted the code somewhere, but I forget the name.
Title: Re: How does one know if a process has stopped or crash?
Post by: dedndave on January 04, 2014, 03:25:17 AM
that sounds like SEH (structured exception handling)
Title: Re: How does one know if a process has stopped or crash?
Post by: Adamanteus on January 04, 2014, 09:01:19 AM
That's crash need more exact defination, as decision could be and SEH handler and terminate process API and mutexes and conditional variables, and may be something else ...
Title: Re: How does one know if a process has stopped or crash?
Post by: jj2007 on January 05, 2014, 09:45:30 PM
Quote from: xanatose on January 03, 2014, 01:22:38 AMwhen one process crash, the other stays waiting forever.

qWord's proposals work, of course, but you better use Task Manager to kill the hanging process while looking for the design flaw that makes it hang. There is absolutely no valid reason why a process should crash with no warning...