#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdio.h>

void segv(int sig) {
	int status;
	pid_t p = fork();
	if (p == -1)
		abort();
	if (p == 0) {
		char pid[10];
		snprintf(pid, 10, "%d", getppid());
		execlp("gdb", "gdb", "-p", pid);
		abort();
	}
	waitpid(p, &status, 0);
	_exit(2);
}

int main() {
	int *a = NULL;
	int b;
	signal(SIGSEGV, segv);
	b = *a;
	return 0;
}

