2025-04-04 19:56:54 +02:00
|
|
|
/* ************************************************************************** */
|
|
|
|
|
/* */
|
|
|
|
|
/* ::: :::::::: */
|
|
|
|
|
/* do_waitpid.c :+: :+: :+: */
|
|
|
|
|
/* +:+ +:+ +:+ */
|
|
|
|
|
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
|
|
|
|
/* +#+#+#+#+#+ +#+ */
|
|
|
|
|
/* Created: 2025/04/04 19:55:22 by khais #+# #+# */
|
2025-04-28 12:30:39 +02:00
|
|
|
/* Updated: 2025/04/28 12:29:50 by khais ### ########.fr */
|
2025-04-04 19:56:54 +02:00
|
|
|
/* */
|
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
|
|
|
|
#include "do_waitpid.h"
|
|
|
|
|
#include "libft.h"
|
|
|
|
|
#include <signal.h>
|
|
|
|
|
#include <sys/wait.h>
|
2025-04-28 12:30:39 +02:00
|
|
|
#include <stdio.h>
|
2025-04-04 19:56:54 +02:00
|
|
|
|
|
|
|
|
void do_waitpid(t_minishell *app, int pid)
|
|
|
|
|
{
|
|
|
|
|
int wstatus;
|
|
|
|
|
|
2025-04-28 12:30:39 +02:00
|
|
|
wstatus = 0;
|
|
|
|
|
if (waitpid(pid, &wstatus, 0) == -1)
|
|
|
|
|
{
|
|
|
|
|
app->last_return_value = 255;
|
|
|
|
|
perror("waitpid");
|
|
|
|
|
}
|
2025-04-04 19:56:54 +02:00
|
|
|
if (WIFEXITED(wstatus))
|
|
|
|
|
app->last_return_value = WEXITSTATUS(wstatus);
|
|
|
|
|
if (WIFSIGNALED(wstatus))
|
|
|
|
|
{
|
|
|
|
|
app->last_return_value = 128 + WTERMSIG(wstatus);
|
|
|
|
|
if (WTERMSIG(wstatus) == SIGQUIT)
|
|
|
|
|
ft_dprintf(STDERR_FILENO, "Quit (core dumped)");
|
|
|
|
|
}
|
|
|
|
|
}
|