|
|
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
1.1.1.2 ! root 8: * generated by a DosFlagProcess api call.
1.1 root 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.
1.1.1.2 ! root 16: *
! 17: * Created by Microsoft Corp. 1986
1.1 root 18: */
19:
1.1.1.2 ! root 20: #define INCL_DOSSIGNALS
! 21: #define INCL_DOSMISC
1.1 root 22:
1.1.1.2 ! root 23: #include <os2def.h>
! 24: #include <bse.h>
! 25: #include <stdio.h>
1.1 root 26:
1.1.1.2 ! root 27: void APIENTRY sig_handler();
1.1 root 28:
29: void main() {
30:
1.1.1.2 ! root 31: char c;
! 32: PFNSIGHANDLER address;
! 33: USHORT oldaction;
! 34: unsigned result;
! 35:
! 36: if (result = DosSetSigHandler(sig_handler, &address,
! 37: &oldaction, SIGA_ACCEPT, SIGA_IGNORE))
1.1 root 38:
39: fprintf(stderr,"dossetsighandler failed %d\n", result);
40:
1.1.1.2 ! root 41: if (result = DosSetSigHandler(sig_handler, &address,
! 42: &oldaction, SIGA_ACCEPT, SIGA_ERROR))
1.1 root 43:
44: fprintf(stderr,"dossetsighandler failed %d\n", result);
45:
1.1.1.2 ! root 46: if( DosGetMachineMode( &c))
! 47: if (result = DosSetSigHandler(sig_handler, &address,
! 48: &oldaction, SIGA_ACCEPT,
! 49: SIGA_ACKNOWLEDGE ))
1.1 root 50: fprintf(stderr,"dossetsighandler failed %d\n", result);
51:
52: do
1.1.1.2 ! root 53: printf("Type a SPACE to terminate demo\n");
1.1 root 54: while(getchar() != 0x20);
55:
56: fprintf(stderr,"Program terminating\n");
57: exit(0);
58: }
59: /*
60: * The signal handler routine must ACKNOWLEDGE the signal before it can
61: * capture another (of the same number). Since this routine runs as
62: * thread 0 it can be preempted by another. If it is
63: * important that all signals be caught, then Thread 0 should be run as
64: * a high priority thread and always snoozing. Of course, the
65: * acknowlegement should be the first thing done in the handler.
66: */
1.1.1.2 ! root 67: void APIENTRY sig_handler(sig_arg, sig_num)
! 68: USHORT sig_arg, sig_num;
1.1 root 69: {
1.1.1.2 ! root 70: USHORT signum, sigarg;
! 71: PFNSIGHANDLER address;
1.1 root 72: int count;
73:
74: fprintf(stderr, "signum %u sigarg %u\n", sig_num, sig_arg);
75:
1.1.1.2 ! root 76: if (count = DosSetSigHandler( (void (pascal far *)())0L,
! 77: &address,
! 78: &sigarg, SIGA_ACKNOWLEDGE, sig_num))
1.1 root 79:
80: fprintf(stderr,"dossetsighandler failed %d\n", count);
81: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.