17 May 2012 18:59
Catching SIGSEGV
I am trying to trap a SIGSEGV (also SIGBUS, SIGILL and SIGFPE, but I have not even managed to generate those yet(Continue reading)). I can easily get the program to produce a message "Segmentation Violation" on stderr, but noway can I catch it before getting that message. I have written sigemptyset(&set); sigaddset(&set, SIGUSR1); sigaddset(&set, SIGUSR2); sigaddset(&set, SIGTERM); sigaddset(&set, SIGINT); sigaddset(&set, SIGSEGV); sigaddset(&set, SIGBUS); sigaddset(&set, SIGILL); sigaddset(&set, SIGFPE); sigaddset(&set, SIGSYS); and I have created a pthread which contains sigwait(&set, &signal); printf("Display signal %d\n", signal); switch (signal) { case SIGSEGV: case SIGBUS: case SIGILL: case SIGFPE: case SIGSYS: fatal("Heat failed: %s", strerror(errno)); case SIGTERM: case SIGINT: warn("Heat terminated");
).
I can easily get the program to produce a message "Segmentation Violation" on stderr, but noway can I catch
it before getting that message.
I have written
sigemptyset(&set);
sigaddset(&set, SIGUSR1);
sigaddset(&set, SIGUSR2);
sigaddset(&set, SIGTERM);
sigaddset(&set, SIGINT);
sigaddset(&set, SIGSEGV);
sigaddset(&set, SIGBUS);
sigaddset(&set, SIGILL);
sigaddset(&set, SIGFPE);
sigaddset(&set, SIGSYS);
and I have created a pthread which contains
sigwait(&set, &signal);
printf("Display signal %d\n", signal);
switch (signal) {
case SIGSEGV:
case SIGBUS:
case SIGILL:
case SIGFPE:
case SIGSYS:
fatal("Heat failed: %s", strerror(errno));
case SIGTERM:
case SIGINT:
warn("Heat terminated");
RSS Feed