From 0290132ca0095e5c99e189af53428f09f7fb5d4d Mon Sep 17 00:00:00 2001 From: Lukas Jiriste Date: Sun, 1 Sep 2024 10:20:58 +0200 Subject: [PATCH] Make shell wait for processes to end after signal Before the shell would send the signal to children and assume they terminated. Now it actually still waits for them to terminate. --- src/execution.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/execution.c b/src/execution.c index 0fd24fd..8ee7e80 100644 --- a/src/execution.c +++ b/src/execution.c @@ -6,7 +6,7 @@ /* By: lnikolov size; while (i > 0) { --i; pid = *(pid_t *)ft_vec_access(child_pids, i); - waitpid(pid, NULL, 0); + if (g_last_signal == 0) + waitpid(pid, NULL, 0); if (g_last_signal) { + sig_num = g_last_signal; + g_last_signal = 0; killall(child_pids, g_last_signal); - return ; + i = child_pids->size; } ft_vec_forget(child_pids, i); } ft_vec_free(child_pids, NULL); + if (g_last_signal == 0) + g_last_signal = sig_num; + return ; } void wait_for_return(t_execution_env *env) @@ -1087,8 +1095,6 @@ void wait_for_return(t_execution_env *env) last_pid = *(pid_t *)ft_vec_access(&env->child_pids, env->child_pids.size - 1); waitpid(last_pid, &status, 0); - if (g_last_signal != 0) - killall(&env->child_pids, g_last_signal); if (g_last_signal == 0) if (WIFEXITED(status)) env->ret_val = WEXITSTATUS(status); -- 2.30.2