10.21. Additional Features
In this section, we describe some additional implementation-dependent features of signals.
Some systems provide the array
extern char *sys_siglist;
The array index is the signal number, giving a pointer to the character string name of the signal.
These systems normally provide the function psignal also.
The string msg (which is normally the name of the program) is output to the standard error, followed by a colon and a space, followed by a description of the signal, followed by a newline. This function is similar to perror (Section 1.7).
Another common function is strsignal. This function is similar to strerror (also described in Section 1.7).
Given a signal number, strsignal will return a string that describes the signal. This string can be used by applications to print error messages about signals received.
Solaris provides a couple of functions to map a signal number to a signal name and vice versa.
These functions are useful when writing interactive programs that need to accept and print signal names and numbers.
The sig2str function translates the given signal number into a string and stores the result in the memory pointed to by str. The caller must ensure that the memory is large enough to hold the longest string, including the terminating null byte. Solaris provides the constant SIG2STR_MAX in <signal.h> to define the maximum string length. The string consists of the signal name without the "SIG" prefix. For example, translating SIGKILL would result in the string "KILL" being stored in the str memory buffer.
The str2sig function translates the given name into a signal number. The signal number is stored in the integer pointed to by signop. The name can be either the signal name without the "SIG" prefix or a string representation of the decimal signal number (i.e., "9").
Note that sig2str and str2sig depart from common practice and don't set errno when they fail.