Skip to content

Instantly share code, notes, and snippets.

@giraldeau
Created March 12, 2015 17:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save giraldeau/98f08161e83a7ab800ea to your computer and use it in GitHub Desktop.
Save giraldeau/98f08161e83a7ab800ea to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <execinfo.h>
volatile static int *x = NULL;
volatile static int action = 0;
void bt()
{
int n = 10;
void *buffer[n];
backtrace((void **)&buffer, n);
backtrace_symbols_fd(buffer, n, 2);
}
void crash(int signo)
{
bt();
exit(0);
}
void handler2()
{
bt();
}
void handler1(int signo)
{
volatile int boom;
switch(action) {
case 0:
boom = *x;
break;
case 1:
kill(getpid(), SIGUSR2);
break;
default:
break;
}
}
int main(int argc, char **argv)
{
if (argc == 2)
action = atoi(argv[1]);
printf("action=%d\n", action);
signal(SIGUSR1, handler1);
signal(SIGUSR2, handler2);
signal(SIGSEGV, crash);
kill(getpid(), SIGUSR1);
printf("bye\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment