Guardian Programmer's Guide

Table Of Contents
Fault-Tolerant Programming in C
Guardian Programmer’s Guide 421922-014
27 - 47
Primary and Backup Processing
Function is_backup_process
Function is_backup_process is called by the main program to determine whether
the current process is the primary process or the backup process.
/*Function is_backup_process returns 'true' if the
current process is the backup process and 'false'
otherwise*/
short is_backup_process (void)
{
short process_type;
process_type = PROCESS_GETPAIRINFO_ ();
if (process_type == IS_BACKUP)
return -1; /*true*/
return 0; /*false*/
}
Function main
Function main does the following:
Calls is_backup_process to determine whether it is running as the primary or
backup process.
If it is the primary process, it initializes a backup process and then calls
primary_processing to perform the primary processing activities.
If it is the backup process, it calls backup_processing to perform the backup
processing activities.
/*The main function determines whether it is running as the
primary or backup process and takes appropriate
action.*/
int main (void)
{
if (is_backup_process ())
backup_processing ();
else
{
initialize_backup ();
primary_processing ();
}
}