I have a program developed in C. I added a sigaction inorder to this program to execute some C code before exiting 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 routines 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 stdout, but the program is not finished.
Am I missing sigaction in my code?
source share