如何从信号号获得易于理解的描述? [英] How can I get a human-readable description from a signal number?
问题描述
POSIX标准或其他C标准是否提供了一种从信号编号中恢复有意义的消息的方法,就像strerror()
使得可以从errno
恢复消息一样? Gnu C库具有strsignal()
,但如果可能的话,我希望可以移植到BSD和其他Unix变体中.
Does the POSIX standard or another C standard provide a way to recover a meaningful message from a signal number, in the same way that strerror()
makes it possible to recover a message from errno
? The Gnu C library has strsignal()
, but if possible, I would like something portable to BSD and other Unix variants.
推荐答案
是的,有趣的是,存在一种从POSIX中的信号中获取字符串消息的标准方法.碰巧的是,它是 strsignal()
.从POSIX.1-2008:
Yes, interestingly, there is a standard way to get a string message from a signal in POSIX. It is, quite coincidentally, strsignal()
. From POSIX.1-2008:
strsignal()函数应将信号编号中的信号编号映射到实现定义的字符串,并应返回指向它的指针.它应使用与psignal()函数相同的消息集.
The strsignal() function shall map the signal number in signum to an implementation-defined string and shall return a pointer to it. It shall use the same set of messages as the psignal() function.
不为您提供此功能的环境不兼容POSIX.尽管相对较新(问题7于2008年问世),但我在
An environment that does not provide you this function is not POSIX-compliant. Although relatively new (Issue 7 came out in 2008), I have a man page for strsignal()
on Mac OS X, so that's a good sign.
这篇关于如何从信号号获得易于理解的描述?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!