This commit is contained in:
Laureηt 2021-04-24 21:16:17 +02:00
parent 13273c5d4f
commit 647706c91e
3 changed files with 20 additions and 26 deletions

BIN
Q1

Binary file not shown.

BIN
minishell

Binary file not shown.

View file

@ -45,7 +45,7 @@ void handler_sigchld(int sig_num)
if (WIFSTOPPED(wait_code))
{
printf("[%d] %d suspended: %s\n", job->id, job->pid, job->cmd);
printf("[%d] %d stopped: %s\n", job->id, job->pid, job->cmd);
}
else if (WIFCONTINUED(wait_code))
{
@ -53,22 +53,22 @@ void handler_sigchld(int sig_num)
}
else if (WIFEXITED(wait_code))
{
printf("[%d] %d done: %s\n", job->id, job->pid, job->cmd);
printf("[%d] %d exited: %s\n", job->id, job->pid, job->cmd);
supprimer(&jobs, job->pid);
}
else if (wait_code == 9) // SIGKILL
else if (wait_code == SIGKILL)
{
printf("[%d] %d killed: %s\n", job->id, job->pid, job->cmd);
supprimer(&jobs, job->pid);
}
}
} while (pid_fils > 0);
if (prompting)
{
siglongjmp(goto_prompt, sig_num);
}
}
} while (pid_fils > 0);
}
void handler_sigint(int sig_num)
{
@ -93,22 +93,6 @@ void handler_sigtstp(int sig_num)
siglongjmp(goto_prompt, sig_num);
}
void attendre(int pid)
{
pid_t id = waitpid(pid, &wait_code, 0); // on attend la fin de l'exec du fils
if (id == -1)
{ // wait fail ?
fprintf(stderr, "ERROR: waiting for %d failed, (%d) %s\n", wait_code, errno, strerror(errno));
exit(errno);
}
if (wait_code)
{ // execvp fail ?
fprintf(stderr, "ERROR: %d's execution failed, (%d) %s\n", pid, wait_code, strerror(wait_code));
}
}
int main(int argc, char *argv[])
{
initialiser(&jobs);
@ -201,7 +185,6 @@ int main(int argc, char *argv[])
}
kill(job->pid, SIGCONT);
pause();
attendre(job->pid);
continue;
}
else if (!strcmp(cmd->seq[0][0], "stop"))
@ -251,7 +234,18 @@ int main(int argc, char *argv[])
}
else
{ // foreground
attendre(pid_fils);
pid_t id = waitpid(pid_fils, &wait_code, 0);
if (id == -1)
{ // wait fail ?
fprintf(stderr, "ERROR: waiting for %d failed, (%d) %s\n", wait_code, errno, strerror(errno));
exit(errno);
}
if (wait_code)
{ // execvp fail ?
fprintf(stderr, "ERROR: command failed, (%d) %s\n", wait_code, strerror(wait_code));
}
}
}
}