added an interupt handler has SIGINT was being ignored... ?
[physics.git] / src / handleSignal.cpp
1 #include "handleSignal.h"
2
3 #include <iostream>
4 #include <signal.h>
5
6 /// ***** Private Method Headers *****
7 void sighandler( int sig );
8
9
10 /// ***** Public Methods *****
11
12 void installSignal()
13 {
14     // register signal handler
15     struct sigaction sa;
16     sigemptyset( &sa.sa_mask );
17     sa.sa_handler = sighandler;
18     sa.sa_flags = 0;
19
20     if ( sigaction( SIGINT, &sa, NULL ) < 0 )
21     {
22         std::cerr << "could not install SIGINT handler" << std::endl;
23     }
24 }
25
26 /// ***** Private Methods *****
27
28 // signal handler function
29 void sighandler( int sig )
30 {
31     switch(sig)
32     {
33         case SIGINT:
34             std::cerr << "SIGINT caught" << std::endl;
35             break;
36         default:
37             std::cout << "UNKNOWN caught";
38     }
39
40     // normally an abort is better ... but this is just SIGINT
41     exit(sig);
42 }