Guardian Programmer's Guide

Table Of Contents
Fault-Tolerant Programming in C
Guardian Programmer’s Guide 421922-014
27 - 52
Active Backup Example 2
*name = terminal_p;
}
Compiling and Running the Debugging Example
To compile the program for use with the Inspect tool, specify the symbols and
inspect pragmas on the compiler command line.
To run the program with the Inspect tool, first locate two terminals. Then do the
following:
1. On the terminal to be used for the backup process, enter PAUSE. This allows the
backup process to gain control of the terminal when it begins executing.
2. On the terminal to be used for the primary process, begin execution of the
program by entering:
rund object-file $primary-terminal $backup-terminal
Active Backup Example 2
This example illustrates active backup programming for an application that performs
simple I/O operations using the standard output file and files other than the standard
input and standard output files. The application consists of a loop that reads a number
from a file and writes the number to another file. The input and output file names are
passed to the application as input parameters.
The file input to the application is a C file (type 180) with a number on each line. To
create this file, first use a text editor to create an EDIT file, then convert the EDIT file to
a C file with the command:
edittoc editfile, cfile
The application, without any code to make it fault-tolerant, is as follows:
/*This application consists of a loop that reads a number from a
file and writes it to another file*/
#pragma ansistreams /*Create type 180 file*/
#include <stdioh> nolist
#include (stdlibh) nolist
/*File pointers*/
FILE *infile;
FILE *outfile;
int main (int argc, char *argv[])
{
short counter;
char sp[10];
/*Verify at least 2 run-time arguments provided*/
if (argc < 3)