This commit is contained in:
Laureηt 2021-04-20 21:42:13 +02:00
parent 262373aab7
commit ba0df8b7cd

View file

@ -29,6 +29,18 @@ void handler_print(int signal_num, siginfo_t *info)
}
}
void handler_int(int signal_num, siginfo_t *info)
{
printf("test\n");
longjmp(start, signal_num);
}
void handler_stop(int signal_num, siginfo_t *info)
{
printf("bye\n");
longjmp(end, signal_num);
}
int main(int argc, char *argv[])
{
@ -38,7 +50,7 @@ int main(int argc, char *argv[])
// gestion de SIGCHLD
struct sigaction action;
action.sa_flags = SA_SIGINFO | SA_RESTART;
action.sa_flags = SA_SIGINFO; //| SA_RESTART;
action.sa_handler = handler_print;
sigemptyset(&action.sa_mask);
sigaction(SIGCHLD, &action, NULL);
@ -110,13 +122,23 @@ int main(int argc, char *argv[])
}
else
{ // on attend le fils, si foreground
jmp_buf env;
setjmp(env); // sauvegarde pour un jump
int codeTerm;
pid_t idFils = waitpid(pidFils, &codeTerm, 0); // on attend la fin de l'exec du fils
if (idFils == -1)
{ // si le wait fail
fprintf(stderr, "ERROR: waiting for %d failed, (%d) %s\n", codeTerm, errno, strerror(errno));
exit(errno);
if (errno == 4)
{
longjmp(env, 1); // si interruption du wait, on jump
}
else
{
fprintf(stderr, "ERROR: waiting for %d failed, (%d) %s\n", codeTerm, errno, strerror(errno));
exit(errno);
}
}
if (codeTerm)