Software watchdog: Don't let your program not respond

Source: Internet
Author: User

A Overview

Some important program must keep it running, and always care about its state------------can't let it deadlock. Of course, if a main program has a deadlock, it must be a design or programming error. The first thing we do is to get this bug out. But if the time is tight, this bug and "erratic", then, we still write a software "watchdog", temporarily should be urgent.

Description of "Watchdog" requirements: "Watchdog" 's operation does not appear the interface window, has certain concealment; Determines whether the target process is running on the current system, if not, starts the target process, determines whether the target process is "not responding", and if so, terminates the target process; If the target process "does not respond" exceeds a certain number of times, the computer system is restarted.

Two Preliminary knowledge

First, we will introduce two main functions to determine whether the target process is "not responding". In User32.dll (no document is exposed), win2k/nt under the Ishungappwindow and Win9x under the Ishungthread, the former is a window handle as a parameter, the latter is the thread ID as the parameter. We can use the VC development tool depends to find these two functions.

To use these two functions, we must first dynamically import the following:

if (m_hUser32 == NULL)
{
   m_hUser32 = GetModuleHandle("USER32.DLL");
}
if (m_hUser32)
{
   m_IsHungNT = (HUNG_FUNNT) GetProcAddress(m_hUser32, "IsHungAppWindow");
   m_IsHung9X = (HUNG_FUN9X) GetProcAddress(m_hUser32, "IsHungThread");
}

In addition, there are the following points of knowledge:

1. How to hide the window (of course, you can still see it through Windows Task Manager)

Modify the window style in the PreCreateWindow of the frame window class as follows:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.