I have this solution for an exercise I was doing but when I try to run it
and send SIGUSR1
the terminal shows "Stack fault", and I don't know why.
It shows nothing when I send SIGUSR2
, but the thing is that with SIGTERM
and SIGINT
the program works.
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <signal.h>
#include <unistd.h>
void manejador(int signum){
switch (signum){
case SIGUSR1:
printf("He recibido la señal SIGUSR1\n");
break;
case SIGUSR2:
printf("He recibido la señal SIGUSR2\n");
break;
case SIGTERM:
printf("Fin de ejecucion\n");
exit(EXIT_SUCCESS);
}
}
int main(int argc, char *argv[])
{
if (signal(SIGUSR1, manejador) == SIG_ERR) {
perror("error en la señal SIGUSR1");
exit(EXIT_FAILURE);
}
if (signal(SIGUSR2, manejador) == SIG_ERR) {
perror("error en la señal SIGUSR2");
exit(EXIT_FAILURE);
}
if (signal(SIGTERM, manejador) == SIG_ERR) {
perror("error en SIGTERM");
exit(EXIT_FAILURE);
}
if (signal(SIGINT, SIG_IGN) == SIG_ERR) {
perror("error en SIGINT");
exit(EXIT_FAILURE);
}
while (1)
pause();
}