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: