I trying to make program reload itself after it receives signal. I have this code
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
void signal_callback_handler(int signum){
printf("Caught signal %d\n",signum);
execv("./test", NULL); //reexec myself
}
int main()
{
signal(SIGINT, signal_callback_handler);
printf("Program STARTED\n");
while(1){
printf("Program processing stuff here.\n");
sleep(1);
}
return EXIT_SUCCESS;
}
The problem is that after exec program just ignore signal instead of calling signal handler. Output:
Program STARTED
Program processing stuff here.
Program processing stuff here.
^CCaught signal 2
Program STARTED
Program processing stuff here.
^C^CProgram processing stuff here.
^C^C^C^C^CProgram processing stuff here.
^C^CProgram processing stuff here.
How to make signal handlers work after exec?