You can define your own termination function to perform program termination tasks such as closing databases and disconnecting communication links in case of terminal processing errors. When you define a custom server, you can specify the name of a termination user function. This function is linked with your other user functions and the main() function in the build process. You can use a termination user function with a main() function you have written, or a system-generated one.
The termination user function is called automatically when the system is shut down by the system administrator.
The SIGINT signal is used to request a custom server to terminate gracefully. When a custom server calls the CA_Init() subroutine, a signal handler for the SIGINT signal is provided that calls the specified termination user function.
When you terminate a custom server, a SIGINT signal is sent to the custom server, which, in turn, sets a terminate flag. Every time the custom server invokes one of the custom server subroutines, this flag is examined and, if it has been set, the termination user function is invoked and the custom server exits. If a user function includes a program loop that does not have any exit criteria, the loop must contain at least one custom server subroutine, otherwise the custom server will not terminate successfully.
An example of a termination user function:
extern FILE *file1_fp; extern FILE *file2_fp; void close_files(void) { fclose(file1_fp); fclose(file2_fp); return;
}
Notes:
To define a termination user function, see Defining the main() function.