xref: /llvm-project/lldb/test/API/functionalities/signal/raise/main.c (revision 99451b4453688a94c6014cac233d371ab4cc342d)
1 #include <signal.h>
2 #include <stdio.h>
3 #include <string.h>
4 #include <unistd.h>
5 
handler(int signo)6 void handler(int signo)
7 {
8     _exit(signo);
9 }
10 
main(int argc,char * argv[])11 int main (int argc, char *argv[])
12 {
13     if (signal(SIGTRAP, handler) == SIG_ERR)
14     {
15         perror("signal(SIGTRAP)");
16         return 1;
17     }
18 #ifndef __APPLE__
19     // Real time signals not supported on apple platforms.
20     if (signal(SIGRTMIN, handler) == SIG_ERR)
21     {
22         perror("signal(SIGRTMIN)");
23         return 1;
24     }
25 #endif
26 
27     if (argc < 2)
28     {
29         puts("Please specify a signal to raise");
30         return 1;
31     }
32 
33     if (strcmp(argv[1], "SIGSTOP") == 0)
34         raise(SIGSTOP);
35     else if (strcmp(argv[1], "SIGTRAP") == 0)
36         raise(SIGTRAP);
37 #ifndef __APPLE__
38     else if (strcmp(argv[1], "SIGRTMIN") == 0)
39         raise(SIGRTMIN);
40 #endif
41     else
42     {
43         printf("Unknown signal: %s\n", argv[1]);
44         return 1;
45     }
46 
47     return 0;
48 }
49 
50