I've a program, which installs a signal handler for SIGSEGV
. In signal handler ( I try to catch crash ) I restart my application.
But when my application is resurrected it doesn't handle SIGSEGV
anymore.
Here's an example:
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
const char * app = 0;
void sig_handler(int signo)
{
puts("sig_handler");
const pid_t p = fork();
if (p == 0)
{
printf("Running app %s\n", app);
execl(app, 0);
}
exit(1);
}
int main(int argc, char** argv)
{
app = argv[0];
struct sigaction act;
sigemptyset(&act.sa_mask);
act.sa_handler = sig_handler;
act.sa_flags = 0;
const int status = sigaction(SIGSEGV, &act, 0) == 0;
printf("signaction = %d\n", status);
sleep(5);
int* a = 0;
int b = *a;
return 0;
}
what I get in output is:
./signals
signaction = 1
sig_handler
Running app ./signals
signaction = 1
So I can see sighandler was set in right way, but resurrected app simply crashed silently.
What am I missing?