|
|
1.1 ! root 1: /* ! 2: * signal.c ! 3: * ! 4: * This example shows the useage of the signal handling capabilities of ! 5: * OS/2. The signal handler is declared as a far pascal routine. It ! 6: * expects two paramters on the stack: the signal number and, optionally, ! 7: * a user defined argument. The latter has meaning only when the signal was ! 8: * generated by a DOSFLAGPROCESS api call. ! 9: * ! 10: * In general the signal handler can be thought of as an interrupt to ! 11: * the current running thread of a process. Thread scheduling is still ! 12: * active. ! 13: * ! 14: * After a signal has been caught, the handler must "acknowledge" the signal ! 15: * before a second one can be handled. ! 16: */ ! 17: ! 18: #include <doscalls.h> ! 19: #include <subcalls.h> ! 20: #include <stdio.h> ! 21: ! 22: #define SIGINTR 1 ! 23: #define SIGTERM 3 ! 24: #define SIGBREAK 4 ! 25: #define CATCH_SIG 2 ! 26: #define SIG_ACK 4 ! 27: ! 28: void pascal far sig_handler(); ! 29: ! 30: void main() { ! 31: ! 32: char c; ! 33: void (pascal far *address)(); ! 34: unsigned oldaction; ! 35: unsigned result; ! 36: ! 37: if (result = DOSSETSIGHANDLER(sig_handler, ! 38: (unsigned long far *) &address, ! 39: (unsigned far *) &oldaction, ! 40: CATCH_SIG, SIGINTR)) ! 41: ! 42: fprintf(stderr,"dossetsighandler failed %d\n", result); ! 43: ! 44: if (result = DOSSETSIGHANDLER(sig_handler, ! 45: (unsigned long far *) &address, ! 46: (unsigned far *) &oldaction, ! 47: CATCH_SIG, SIGTERM)) ! 48: ! 49: fprintf(stderr,"dossetsighandler failed %d\n", result); ! 50: ! 51: if( DOSGETMACHINEMODE( &c)) ! 52: if (result = DOSSETSIGHANDLER(sig_handler, ! 53: (unsigned long far *) &address, ! 54: (unsigned far *) &oldaction, ! 55: CATCH_SIG, SIGBREAK)) ! 56: ! 57: fprintf(stderr,"dossetsighandler failed %d\n", result); ! 58: ! 59: do ! 60: printf("Type an SPACE to terminate demo\n"); ! 61: while(getchar() != 0x20); ! 62: ! 63: fprintf(stderr,"Program terminating\n"); ! 64: exit(0); ! 65: } ! 66: /* ! 67: * The signal handler routine must ACKNOWLEDGE the signal before it can ! 68: * capture another (of the same number). Since this routine runs as ! 69: * thread 0 it can be preempted by another. If it is ! 70: * important that all signals be caught, then Thread 0 should be run as ! 71: * a high priority thread and always snoozing. Of course, the ! 72: * acknowlegement should be the first thing done in the handler. ! 73: */ ! 74: void pascal far sig_handler(sig_arg, sig_num) ! 75: unsigned sig_arg, sig_num; ! 76: { ! 77: unsigned signum, sigarg; ! 78: long address; ! 79: int count; ! 80: ! 81: fprintf(stderr, "signum %u sigarg %u\n", sig_num, sig_arg); ! 82: ! 83: if (count = DOSSETSIGHANDLER( (void (far *)())0L, ! 84: (unsigned long far *) &address, ! 85: (unsigned far *) &sigarg, ! 86: SIG_ACK, sig_num)) ! 87: ! 88: fprintf(stderr,"dossetsighandler failed %d\n", count); ! 89: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.