A critical process monitor is a system service implemented as software, firmware, and hardware that keeps critical processes running at all times. If a critical process stops running, an Auto PC ceases to function fully. A critical process must regularly notify the critical process monitor that the process is running properly. If a process is not running properly, the OS can restart the improperly running process.
In addition to monitoring individual processes, a critical process monitor notifies a hardware watchdog timer at least once every four seconds to demonstrate that an Auto PC is still active. If the notification fails to occur, the hardware forces an Auto PC to reboot.
The following illustration shows the relationship between applications and the components of the critical process monitor.
You call critical process monitor functions to register your application with a critical process monitor and to regularly notify that critical process monitor. You can provide a callback function that the critical process monitor can call to clean up after your application, if the critical process monitor needs to terminate your application. When your application no longer qualifies as a critical process, you can also call a function to notify the critical process monitor of this change.
If your application does not notify the critical process monitor within this interval, the critical process monitor considers your application to be an improperly running process.
The following code example shows how to register an application as a critical process.
dwProcessId = GetCurrentProcessID ();
if (!CPMRegister (dwProcessId, 1000, CPM_RELAUNCH, szAppName, pCallback,
CPM_RELAUNCH_FAIL_OK))
{
// If an error occurs, handle it here.
}
The following code example shows how to create a notification loop.
while (TRUE)
{
Sleep(500);
// You must provide code that determines if the application
// continues to function properly.
CPMNotify (dwProcessId);
}
The following code example shows how to create a callback function. The name of the function is pCallback, rather than CPMCallback. The two parameters are specified in CPMCallback and the function is called with CPM_CLEANUP.
Void pCallback (DWORD dwCmd, DWORD dwCmdInfo)
{
ASSERT (dwCmd == CPM_CLEANUP);
// You must provide code to save open data files, and you
// must save the status of the running application.
}
To notify the critical process monitor that a process is no longer critical, call CPMUnRegister with the same process identifier that you used to register the process.