gestion des signaux avec execve ok dans test

This commit is contained in:
hugogogo
2021-11-15 21:56:50 +01:00
parent 57c271b9e2
commit 36766501ba
5 changed files with 51 additions and 8 deletions

View File

@@ -27,6 +27,8 @@ int main(int argc, char *argv[], char *envp[])
char *line_input;
char *prompt;
pid_t pid;
char **argvtmp;
int wstatus;
signal(SIGINT, handler_sigint); // signal handling for SINGINT while interactive mode
line_input = NULL;
@@ -43,7 +45,15 @@ int main(int argc, char *argv[], char *envp[])
if (pid == 0)
{
signal(SIGINT, handler_sigint_execution); // start signal handling for SIGINT in child process
if (!strncmp("echo", line_input, 4))
if (!strncmp("sleep", line_input, 5))
{
argvtmp = malloc(sizeof(char*) * 3);
argvtmp[0] = strdup("sleep");
argvtmp[1] = strdup("2");
argvtmp[2] = NULL;
execve("/bin/sleep", argvtmp, envp);
}
else if (!strncmp("echo", line_input, 4))
{
write(1, "3", 2);
sleep(1);
@@ -68,7 +78,13 @@ int main(int argc, char *argv[], char *envp[])
}
}
else
wait(0);
{
wait(&wstatus);
if (WIFEXITED(wstatus))
write(1, "the child terminated normally\n", 30);
if (WIFSIGNALED(wstatus))
write(1, "the child was terminated by a signal\n", 37);
}
signal(SIGINT, handler_sigint); // restart signal handling for SIGINT because re-entring in interactive mode
}
else if (!line_input)