This source file includes following definitions.
- sigusr_handler
- exit_handler
- main
1
2
3
4
5
6
7 #include "orte_config.h"
8
9 #include <stdio.h>
10 #include <signal.h>
11
12 #include "orte/util/name_fns.h"
13 #include "orte/util/proc_info.h"
14 #include "orte/runtime/orte_globals.h"
15 #include "orte/runtime/runtime.h"
16
17
18
19
20 void sigusr_handler(int signum)
21 {
22 switch (signum) {
23 case SIGUSR1:
24 fprintf(stderr, "%s Trapped SIGUSR1\n", ORTE_NAME_PRINT(ORTE_PROC_MY_NAME));
25 break;
26
27 case SIGUSR2:
28 fprintf(stderr, "%s Trapped SIGUSR2\n", ORTE_NAME_PRINT(ORTE_PROC_MY_NAME));
29 return;
30
31 case SIGCONT:
32 fprintf(stderr, "%s Trapped SIGCONT\n", ORTE_NAME_PRINT(ORTE_PROC_MY_NAME));
33 return;
34
35 default:
36 fprintf(stderr, "%s Undefined signal %d trapped\n", ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), signum);
37 return;
38 }
39 }
40
41 void exit_handler(int signum)
42 {
43 int rc;
44
45 switch (signum) {
46 case SIGINT:
47 fprintf(stderr, "%s Trapped SIGINT\n", ORTE_NAME_PRINT(ORTE_PROC_MY_NAME));
48 break;
49
50 case SIGHUP:
51 fprintf(stderr, "%s Trapped SIGHUP\n", ORTE_NAME_PRINT(ORTE_PROC_MY_NAME));
52 break;
53
54 case SIGTERM:
55 fprintf(stderr, "%s Trapped SIGTERM\n", ORTE_NAME_PRINT(ORTE_PROC_MY_NAME));
56 break;
57
58 default:
59 fprintf(stderr, "%s Undefined signal %d trapped\n", ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), signum);
60 break;
61 }
62 return;
63
64 exit(1);
65 }
66
67
68 int main(int argc, char* argv[])
69 {
70
71 int rc;
72 int i;
73 double pi;
74
75 orte_init(&argc, &argv, ORTE_PROC_TOOL);
76
77 if (signal(SIGUSR1, sigusr_handler) == SIG_IGN) {
78 fprintf(stderr, "Could not setup signal trap for SIGUSR1\n");
79 exit(1);
80 }
81
82 if (signal(SIGUSR2, sigusr_handler) == SIG_IGN) {
83 fprintf(stderr, "Could not setup signal trap for SIGUSR2\n");
84 exit(1);
85 }
86
87 if (signal(SIGCONT, sigusr_handler) == SIG_IGN) {
88 fprintf(stderr, "Could not setup signal trap for SIGUSR2\n");
89 exit(1);
90 }
91
92 if (signal(SIGINT, exit_handler) == SIG_IGN) {
93 fprintf(stderr, "Could not setup signal trap for SIGINT\n");
94 exit(1);
95 }
96
97 if (signal(SIGHUP, exit_handler) == SIG_IGN) {
98 fprintf(stderr, "Could not setup signal trap for SIGHUP\n");
99 exit(1);
100 }
101
102 if (signal(SIGTERM, exit_handler) == SIG_IGN) {
103 fprintf(stderr, "Could not setup signal trap for SIGTERM\n");
104 exit(1);
105 }
106
107 i = 0;
108 while (1) {
109 i++;
110 pi = i / 3.14159256;
111 if (i > 100) i = 0;
112 }
113
114 return 0;
115 }