Previous Topic Next topic Print topic


Example of Posting a Signal Handler

Restriction: The following applies to native COBOL only.

The following example illustrates posting a signal handler for the SIGABRT signal:

#include <stdio.h>
#include <signal.h>
#include "cobtypes.h"
#include "cobsignal.h"
#include "cobmain.h"

int
mysigcatch(int sig, cobsiginfo_t * mf_info)
{
     printf("In signal handler for sig %d\n", sig);
     return 0;  /* Do not process any further handlers. */
}                 

void
mysigexit(cobsigtype_t sighand)
{
    printf("Cancelling handler\n");
    cobremovesighandler(sighand);       /* Remove the handler. */
}               

int
main(int argc, char *argv[])
{
    cobsigtype_t sighandle;

    cobinit();

    sighandle = cobpostsighandler(SIGABRT, 128, mysigcatch);
    if(sighandle)
    {
        /* Call a cobol program using cobfunc function. */
        cobfunc("cobolprog", argc, argv);

        raise(SIGABRT); /* Raise the signal. */
        mysigexit(sighandle);
    }

    cobexit(0); /* Cobexit - close down COBOL run-time environment. */
}                               

Previous Topic Next topic Print topic