Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
428 views
in Technique[技术] by (71.8m points)

windows xp - Best way to detect an application crash and restart it?

What's the best way to detect an application crash in XP (produces the same pair of 'error' windows each time - each with same window title) and then restart it?

I'm especially interested to hear of solutions that use minimal system resources as the system in question is quite old.

I had thought of using a scripting language like AutoIt (http://www.autoitscript.com/autoit3/), and perhaps triggering a 'detector' script every few minutes?

Would this be better done in Python, Perl, PowerShell or something else entirely?

Any ideas, tips, or thoughts much appreciated.

EDIT: It doesn't actually crash (i.e. exit/terminate - thanks @tialaramex). It displays a dialog waiting for user input, followed by another dialog waiting for further user input, then it actually exits. It's these dialogs that I'd like to detect and deal with.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Best way is to use a named mutex.

  1. Start your application.
  2. Create a new named mutex and take ownership over it
  3. Start a new process (process not thread) or a new application, what you preffer.
  4. From that process / application try to aquire the mutex. The process will block
  5. When application finish release the mutex (signal it)
  6. The "control" process will only aquire the mutex if either the application finishes or the application crashes.
  7. Test the resulting state after aquiring the mutex. If the application had crashed it will be WAIT_ABANDONED

Explanation: When a thread finishes without releasing the mutex any other process waiting for it can aquire it but it will obtain a WAIT_ABANDONED as return value, meaning the mutex is abandoned and therfore the state of the section it was protected can be unsafe.

This way your second app won't consume any CPU cycles as it will keep waiting for the mutex (and that's enterely handled by the operating system)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...