This is the function I use to make process A sleep a random amount of time
int sd_sleepRandomTime() {
debug("SD15", "<");
srand(time(NULL));
int sec = rand()%((MAX_PROCESSAMENTO)-MIN_PROCESSAMENTO) + MIN_PROCESSAMENTO;
success("SD15", "%d", sec);
sleep(sec);
printf("here");
debug("SD15", ">");
return 0;
}
Here is the SIGINT handler I use in process B to send a SIGHUP to process C
void trataSinalSIGINT(int sinalRecebido) {
debug("C9", "<");
kill(pidServidor, SIGHUP);
success("C9", "Processo Cancelado pelo Cliente");
debug("C9", ">");
exit(0);
return;
}
And here is the SIGHUP handler in process C to SIGTERM process A (it only matters starting from "//S11.3" I think)
void trataSinalSIGHUP(int sinalRecebido, siginfo_t *info, void *context) {
debug("S11", "<");
success("S11", "Cancel");
//S11.1
int pid = info->si_pid;
success("S11.1","Cancelamento enviado pelo Processo %d", pid);
//S11.2
int pid_sv=-1;
int ch = 0;
for(int i = 0; i!= NUM_PASSAGENS; i++){
if(lista_passagens[i].pid_cliente==pid){
ch=1;
pid_sv=lista_passagens[i].pid_servidor_dedicado;
success("S11.2", "Cancelamento %d", pid_sv);
}
}
if(ch==0){
error("S11.2","");
}
//S11.3
kill(pid_sv, SIGTERM);
success("S11.3", "Cancelamento Shutdown %d", pid_sv);
debug("S11", ">");
}
For some reason once I Ctrl+C in process B the only thing showing in terminal is Segmentation fault and after that it just completes process A like nothing had happened and without even entering the SIGHUP handler in process C