Solaris provides a couple of functions to map a
signal number to a signal name and vice versa.
#include
<signal.h>
int sig2str(int signo, char *str);
int str2sig(const
char *str, int *signop);
Both return: 0 if OK, 1 on error
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.
No comments:
Post a Comment