Creating a Watch Dog Application

CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.

Environment: C++, Frameworks

The accompanying code takes care of another application (call it “myApp”) that should always be running.

It wakes up every X times, and checks the following:

  1. Is myApp running? If not, it turns it on.
  2. Is myApp hanging? (This is decided by myApp not consuming any CPU usage during the last X times and since the previous check.) If yes, kills it and restarts it.
  3. Is myApp already running for Y time? If yes, kills it and restarts it.

The program keeps a log file of its actions (checking, restarting, killing). It also copies the log file of myApp (if any) to another location (same name, plus date and time concatenated), so that the information in it will not get lost.

This code was compiled under VC++ 6.0. It needs the following definitions:

  • _WIN32
  • WIN32
  • _DEBUG
  • _MBCS


Download source – 3 Kb

More by Author

Previous article
Next article

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read