39 lines
1.3 KiB
C
39 lines
1.3 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* :::::::: */
|
|
/* executor_fork.c :+: :+: */
|
|
/* +:+ */
|
|
/* By: willem <willem@student.codam.nl> +#+ */
|
|
/* +#+ */
|
|
/* Created: 2025/02/12 21:24:52 by willem #+# #+# */
|
|
/* Updated: 2025/02/26 16:10:40 by whaffman ######## odam.nl */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "minishell.h"
|
|
|
|
//TODO should parent close the fds?
|
|
pid_t executor_fork(t_minishell *msh, t_command *command)
|
|
{
|
|
pid_t pid;
|
|
|
|
pid = fork();
|
|
if (pid > 0)
|
|
{
|
|
if (command->fd_in != 0)
|
|
close(command->fd_in);
|
|
if (command->fd_out != 1)
|
|
close(command->fd_out);
|
|
signal_init_parent();
|
|
}
|
|
else if (pid == 0)
|
|
{
|
|
signal_init_child();
|
|
executor_child(msh, command);
|
|
exit(127);
|
|
}
|
|
else
|
|
perror("fork");
|
|
return (pid);
|
|
}
|