Guardian Programmer's Guide

Table Of Contents
Fault-Tolerant Programming in C
Guardian Programmer’s Guide 421922-014
27 - 60
Primary and Backup Processing
process, then calls primary_processing. If it is the backup process, it calls
backup_processing.
Function primary_processing
Function primary_processing does the work of the application (which, in this case,
is to execute a loop that reads numbers from an input file and writes the numbers to an
output file and to the standard output). Within the loop, function update_backup is
called to send file state information to the backup process. If an end-of-file is
encountered in the input file, primary_processing stops the backup process and
returns to the main function. Function primary_processing is as follows:
/*This function performs the real work of the application. It
consists of a loop that reads lines from an input file and
writes them to an output file.*/
void primary_processing (void)
{
short counter;
char string_pointer[10];
for (;;)
{
/*Terminate immediately if end of file*/
if (fgets (string_pointer, 10, infile) == NULL)
exit (0); /*Stops primary and backup processes*/
counter = atoi(string_pointer);
(void) printf ("counter = %d\n", counter);
(void) fprintf (outfile, "%d\n", counter);
fflush (outfile);
update_backup ();
}
}
Function backup_processing
Function backup_processing handles the backup tasks, which include:
Open $RECEIVE so that the backup process can receive messages from the
primary process and the operating system.
Call MONITORCPUS to indicate to the operating system that the backup process
is to be notified if the primary process CPU fails.
Enter an infinite loop that reads and processes messages from $RECEIVE.
If the backup process receives a message indicating that the primary process or CPU
has failed, it does the following:
Creates and starts a new backup process.
Calls primary_processing to continue application processing.