Skip to content

Instantly share code, notes, and snippets.

@orymate
Created March 6, 2012 14:08
Show Gist options
  • Save orymate/1986470 to your computer and use it in GitHub Desktop.
Save orymate/1986470 to your computer and use it in GitHub Desktop.
signal_name.c
#include <signal.h>
const char *getsignalname(int n) {
static const char *names[NSIG];
static bool firstrun = true;
if (firstrun) {
firstrun = false;
names[SIGIOT ] = "SIGIOT";
names[SIGBUS ] = "SIGBUS";
names[SIGSTKFLT] = "SIGSTKFLT";
names[SIGURG ] = "SIGURG";
names[SIGXCPU ] = "SIGXCPU";
names[SIGXFSZ ] = "SIGXFSZ";
names[SIGVTALRM] = "SIGVTALRM";
names[SIGPROF ] = "SIGPROF";
names[SIGWINCH ] = "SIGWINCH";
names[SIGIO ] = "SIGIO";
names[SIGPWR ] = "SIGPWR";
names[SIGSYS ] = "SIGSYS";
// mainstream names:
names[SIGHUP ] = "SIGHUP";
names[SIGINT ] = "SIGINT";
names[SIGQUIT ] = "SIGQUIT";
names[SIGILL ] = "SIGILL";
names[SIGTRAP ] = "SIGTRAP";
names[SIGABRT ] = "SIGABRT";
names[SIGFPE ] = "SIGFPE";
names[SIGKILL ] = "SIGKILL";
names[SIGUSR1 ] = "SIGUSR1";
names[SIGSEGV ] = "SIGSEGV";
names[SIGUSR2 ] = "SIGUSR2";
names[SIGPIPE ] = "SIGPIPE";
names[SIGALRM ] = "SIGALRM";
names[SIGTERM ] = "SIGTERM";
names[SIGCHLD ] = "SIGCHLD";
names[SIGCONT ] = "SIGCONT";
names[SIGSTOP ] = "SIGSTOP";
names[SIGTSTP ] = "SIGTSTP";
names[SIGTTIN ] = "SIGTTIN";
names[SIGTTOU ] = "SIGTTOU";
}
return n>=0 && n<NSIG ? names[n] : "n/a";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment