-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
36 lines (33 loc) · 1.43 KB
/
Copy pathmain.c
File metadata and controls
36 lines (33 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tbui-quo <tbui-quo@student.42wolfsburg.d> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/06/19 18:44:17 by tbui-quo #+# #+# */
/* Updated: 2023/07/04 18:07:18 by tbui-quo ### ########.fr */
/* */
/* ************************************************************************** */
#include "pipex.h"
int main(int argc, char *argv[], char *env[])
{
int pipe_fd[2];
int cmd_index;
pid_t process_id[2];
cmd_index = 1;
if (argc != 5)
return (print_error_msg(ERR_INPUT));
if (pipe(pipe_fd) == -1)
print_error_msg_and_exit(ERR_PIPE);
while (++cmd_index < argc - 1)
{
process_id[cmd_index - 2] = fork();
if (process_id[cmd_index - 2] == 0)
execute_child_process(argv, pipe_fd, env, cmd_index);
if (process_id[cmd_index - 2] == -1)
print_error_msg_and_exit(ERR_FORK);
}
execute_parent_process(pipe_fd, process_id);
return (0);
}