I have a program developed in C. I added to this program a sigaction handler inorder to execute some C code before quit the program:
void signal_term_handler(int sig)
{
printf("EXIT :TERM signal Received!\n");
int rc = flock(pid_file, LOCK_UN | LOCK_NB);
if(rc) {
char *piderr = "PID file unlock failed!";
fprintf(stderr, "%s\n", piderr);
printf(piderr);
}
exit(EXIT_SUCCESS);
}
int main(int argc, char **argv)
{
struct sigaction sigint_action;
sigint_action.sa_handler = &signal_term_handler;
sigemptyset(&sigint_action.sa_mask);
sigint_action.sa_flags = SA_RESETHAND;
sigaction(SIGTERM, &sigint_action, NULL);
...........
}
Note: My program contains 2 subthreads running
When I execute myprogram and then I call kill -15 <pidnumber>
to kill my program. I get the message "EXIT :TERM signal Received!\n
" printed in the stdout but the program is not exited.
Am I missing someting in my sigaction code?