要命名的信号编号? [英] Signal number to name?
本文介绍了要命名的信号编号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从信号编号中快速获取信号名称?有 strsignal()
,但我只想要名字,例如SIGUSR1
How can I quickly get signal name from its number?
There is strsignal()
, but I just want the name, e.g. SIGUSR1
换句话说,如果我们有像这样的宏<代码>SIGUSR1 ->12我们有什么类似的吗<代码>12 ->SIGUSR1 ?
In other words, if we have macros like
SIGUSR1 -> 12
do we have anything like
12 -> SIGUSR1
?
推荐答案
我的 strsignal(3)
手册页说您可以直接从 sys_signame
数组中获取名称.这是我编写的一个简单示例程序来测试它:
My strsignal(3)
man page says you can get the names directly from the sys_signame
array. Here's a simple example program I wrote to test it:
#include <signal.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
void upcase(char *s)
{
while (*s)
{
*s = toupper(*s);
s++;
}
}
int main(void)
{
for (int sig = 1; sig < NSIG; sig++)
{
char *str = strdup(sys_signame[sig]);
if (!str)
return -1;
upcase(str);
printf("%2d -> SIG%s\n", sig, str);
free(str);
}
return 0;
}
我认为这个程序产生了你正在寻找的输出:
I think this program produces the output you're looking for:
$ ./example
1 -> SIGHUP
2 -> SIGINT
3 -> SIGQUIT
4 -> SIGILL
5 -> SIGTRAP
6 -> SIGABRT
7 -> SIGEMT
8 -> SIGFPE
9 -> SIGKILL
10 -> SIGBUS
11 -> SIGSEGV
12 -> SIGSYS
13 -> SIGPIPE
14 -> SIGALRM
15 -> SIGTERM
16 -> SIGURG
17 -> SIGSTOP
18 -> SIGTSTP
19 -> SIGCONT
20 -> SIGCHLD
21 -> SIGTTIN
22 -> SIGTTOU
23 -> SIGIO
24 -> SIGXCPU
25 -> SIGXFSZ
26 -> SIGVTALRM
27 -> SIGPROF
28 -> SIGWINCH
29 -> SIGINFO
30 -> SIGUSR1
31 -> SIGUSR2
这篇关于要命名的信号编号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文