/* By: lnikolov <lnikolov@student.42prague.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/21 08:57:54 by ljiriste #+# #+# */
-/* Updated: 2024/09/01 08:34:42 by ljiriste ### ########.fr */
+/* Updated: 2024/09/01 10:19:33 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
{
size_t i;
pid_t pid;
+ int sig_num;
+ sig_num = 0;
i = child_pids->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)
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);