The following example illustrates posting a signal handler for the SIGABRT signal:
#include <stdio.h> #include <signal.h> #include "cobsignal.h" #include "cobmain.h" int mysigcatch(int sig) { printf("In new signal handler\n"); return(0); /* Do not process any further handlers */ } void mysigexit(cobsigtype_t sighand) { printf("Cancelling handler\n"); cobremovesighandler(sighand); /* Remove the handler */ } main(int argc, char *argv[]) { cobsigtype_t sighandle; cobinit(); sighandle = cobpostsighandler(SIGABRT, 128, mysigcatch); cobfunc("cobolprog", argc, argv); /* call a cobol program using cobfunc function */ raise(SIGABRT); /* raise the signal */ mysigexit(sighandle); cobexit(0); /* Cobexit - close down COBOL run-time environment */ }