Get signal name from signal number
The way to do this in C is to define an array, and use designated array initializers to ensure the correct mapping between number and string, like so:
static const char *signames[] = {
    [SIGKILL] = &quot;SIGKILL&quot;,
    [SIGSTOP] = &quot;SIGSTOP&quot;,
    ...
    [0] = &quot;[NO SIGNAL TO DELIVER]&quot;,
};

const char *getsig(int sig) {
    if (sig &lt; 0 || sig &gt;= sizeof(signames) / sizeof(*signames) || !signames[sig])
        return &quot;UNKN&quot;;

    return signames[sig];
}

Note that it is hard to make this portable; the list of available signals varies by operating system, and some don't even have the concept of signals. Some operating systems and/or standard libraries might already have some function to convert signal numbers to strings, if you target a specific platform and don't care about compatibility, you might consider using that.
Note that strsignal() should be available on any POSIX platform, although it gives you a more human readable string like &quot;Killed&quot; instead of &quot;SIGKILL&quot;.