waiting on all processes before returnning to the read evalloop

This commit is contained in:
whaffman 2025-03-19 14:54:14 +01:00
parent 0e94a5a97a
commit 503486a8e6
4 changed files with 31 additions and 10 deletions

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/05 12:36:08 by whaffman #+# #+# */
/* Updated: 2025/03/04 18:11:00 by whaffman ######## odam.nl */
/* Updated: 2025/03/19 13:46:51 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
@ -66,6 +66,7 @@ typedef struct s_command
int fd_in;
int fd_out;
int n_fds;
int pid;
int exit_status;
} t_command;

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/12 21:25:02 by willem #+# #+# */
/* Updated: 2025/03/07 16:17:26 by whaffman ######## odam.nl */
/* Updated: 2025/03/19 14:03:51 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
@ -48,11 +48,33 @@ static int executor_execute_command(t_minishell *msh, t_command *cmd)
return (0);
}
static void executor_wait(t_minishell*msh)
{
t_list *cur;
int exit_status;
exit_status = 0;
cur = msh->commands;
while (cur)
{
if (((t_command *)cur->content)->pid == 0)
{
cur = cur->next;
continue ;
}
waitpid(((t_command *)cur->content)->pid, &exit_status, 0);
if (WIFEXITED(exit_status))
msh->exit_status = WEXITSTATUS(exit_status);
else
msh->exit_status = WTERMSIG(exit_status) + 128;
cur = cur->next;
}
}
int executor_execute_pipeline(t_minishell *msh)
{
t_list *current;
pid_t last_pid;
int exit_status;
executor_create_pipes(msh);
executor_create_redirects(msh);
@ -64,11 +86,7 @@ int executor_execute_pipeline(t_minishell *msh)
last_pid = executor_execute_command(msh, (t_command *)current->content);
current = current->next;
}
if (last_pid != 0)
{
waitpid(last_pid, &exit_status, 0);
msh->exit_status = ((exit_status) & 0xff00) >> 8;
}
executor_wait(msh);
signal_init_minishell();
return (msh->exit_status);
}

View File

@ -6,7 +6,7 @@
/* By: willem <willem@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/12 21:24:52 by willem #+# #+# */
/* Updated: 2025/03/06 11:34:43 by whaffman ######## odam.nl */
/* Updated: 2025/03/19 13:58:33 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
@ -21,6 +21,7 @@ pid_t executor_fork(t_minishell *msh, t_command *command)
pid = fork();
if (pid > 0)
{
command->pid = pid;
if (command->fd_in != 0)
close(command->fd_in);
if (command->fd_out != 1)

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/11 16:18:21 by qmennen #+# #+# */
/* Updated: 2025/03/04 18:18:09 by whaffman ######## odam.nl */
/* Updated: 2025/03/19 13:47:25 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
@ -23,5 +23,6 @@ t_command *parser_alloc_command(t_minishell *msh)
command->redirect_in = NULL;
command->redirect_out = NULL;
command->n_fds = 0;
command->pid = 0;
return (command);
}