Creating a Watch Dog Application

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
  • _CONSOLE
  • _MBCS
  • UNICODE
  • _UNICODE.

Downloads

Download source - 3 Kb


Comments

  • some people feel they r super human

    Posted by dharani on 06/05/2004 04:18am

    so we need to teach them a lesson when they come out with such what-is-this-code ? sort of remarks . i hope these kinda ppl ill opt out of codeguru for its own sake , bye the bye -i ha been coding for 3 yrs ( thoiugh i know how to kill /create process ) this piece of code is very good to me . good luck author keep it up regards dharani dharani

    Reply
  • VB6

    Posted by Legacy on 02/09/2004 12:00am

    Originally posted by: Anne

    Hi, does anybody have an WATCHDOG for Visual Basic? Thanks, Anne

    Reply
  • of course it can be killed...

    Posted by Legacy on 12/06/2002 12:00am

    Originally posted by: Johan Eliasson

    Where did he write that this code protects your app from being killed by other apps? NOWHERE! I don't think that's the purpose of the program.

    I have this situation: On a remote computer I need an app running 24/7. The app crashes sometimes by simply quitting without saying anything. If that happens I need to make sure that it's started again.

    This program seems to be exactly what I need.

    Thanks!

    Reply
  • good!

    Posted by Legacy on 12/03/2002 12:00am

    Originally posted by: wolfbin

    About the comments... I think the code is selfcommented, so if you are a coder you don't really need much more. ;)

    Reply
  • Stones in Glass houses

    Posted by Legacy on 12/03/2002 12:00am

    Originally posted by: JoAnn

    What is it that makes some people think that it's okay and acceptable to bash someone just because they don't find their contribution useful or "ingenius". I don't come to CodeGuru.com to find some obscure way to code. I come here to learn a new technique and to find solutions. If I already know something, I think, wow, I already know that. If I think I have a better solution, I might contribute it for others to benefit from. I would NEVER dream of bashing someone cause I disagreed with their method, their code style, etc. In fact, I find that I am taken more seriously if I share an honest critique without going out of my way to be rude. I don't think that Tali or any other person submitting code for others' use or edification should become the target of judgemental comments. If you don't like the idea of using API calls, where is your submission addressing the same issue without the API calls? And as for College-ish, well, I have been coding for 4 years now and on occasion I still pull out an old project to refresh an idea or recall how I did something before. I think the purpose here is to provide differing insights, not to tear apart the coder.

    JoAnn

    Reply
  • Very useful

    Posted by Legacy on 12/02/2002 12:00am

    Originally posted by: Marc Clifton

    I had to do something like this recently, and I found it interesting to see your approach.

    Others have posted what I think are incredibly rude comments. You've put together a simple and clean app that does one thing, and one thing well. That's rare. And anyone worth their salt shouldn't need code comments to understand immediately what you're doing. Good grief. Ignore those morons.

    Marc

    Reply
  • Screw the gum-flappers...

    Posted by Legacy on 11/30/2002 12:00am

    Originally posted by: Cloaca

    Don't be discouraged by the gum-flappers here who are not significant. Nice helpful work Tali. Simple, but exactly what some folks (like me) will need.

    Best,
    Eric

    Reply
  • It is junk

    Posted by Legacy on 11/29/2002 12:00am

    Originally posted by: Abdul Kareem

    What is this??? Some junk of API calls.. No comments, No explanation. We are not expecting this type of article at codeguru.com.

    Reply
  • It seems like some explanations are needed here...

    Posted by Legacy on 11/28/2002 12:00am

    Originally posted by: Tali Gat-Falik

    The idea of this article was not to present any "ingenous" code (these parts are considered my company's IP...), but to implement something I needed a few times in the past.

    It's true that I mainly use API calls , but I hope that the framework and putting it all together could help others, even if "help" means saving one hour of coding+debugging...

    By the way, the time calculation there is not trivial - do you know it off-handedly taht each high byte is ~7 minutes?
    otehrwise the transaltion between system time and real minutes is a headacke...

    Reply
  • support comment

    Posted by Legacy on 11/28/2002 12:00am

    Originally posted by: sway

    I have been using MFC mostly. This API code is simple but helpful to me too.
    I believe that the codegueu.com is not only a place like "GURU" club, but also a place where programmers of all levels can find help.
    What is the standard in here? Being able to help some other people is the standard in here. Why this site is the #1? because it's open minded to all ideas, even worng ones.

    Sway

    Reply
  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: November 20, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Are you wanting to target two or more platforms such as iOS, Android, and/or Windows? You are not alone. 90% of enterprises today are targeting two or more platforms. Attend this eSeminar to discover how mobile app developers can rely on one IDE to create applications across platforms and approaches (web, native, and/or hybrid), saving time, money, and effort and introducing apps to market faster. You'll learn the trade-offs for gaining long …

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds