-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpipex_utils.c
65 lines (59 loc) · 2.15 KB
/
pipex_utils.c
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* pipex_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: zkarapet <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/22 19:40:52 by zkarapet #+# #+# */
/* Updated: 2023/03/06 12:41:03 by zkarapet ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void checking_fork(t_args *a, pid_t forking, int i)
{
int j;
j = -1;
a->pids[i + 1] = forking;
if (forking < 0)
{
while (a->pids[++j] != a->pids[i + 1])
kill(a->pids[j], 0);
}
}
// A process terminates normally when its program signals it is done by calling exit. Returning from main is equivalent to calling exit, and the value that main returns is used as the argument to exit. WIFEXITED(status) checks if child terminated normally, WEXITSTATUS(status) generates exit status of child, WTERMSIG(status) macro returns the numeric value of the signal that was raised by the child process
void processing_status(t_args *a, int size)
{
pid_t pid;
int i;
int status;
i = -1;
status = 0;
while (++i < size)
{
pid = waitpid(-1, &status, 0);
if (pid == a->pids[size - 1])
{
if (!WTERMSIG(status)) // child completed successfully
g_status = WEXITSTATUS(status);
else // terminated with failure
{
g_status = WTERMSIG(status) + 128;
if (g_status == 130)
write(1, "\n", 1);
else if (g_status == 131)
ft_putstr_fd("Quit 3", 1, 1);
}
}
}
}
int pipefds_check(int (*pipefds)[2], int i, t_cmd *cur)
{
if (pipe_error(pipe(pipefds[i])))
{
close_pipefds(pipefds, i, cur, 1);
pipefds_free(pipefds);
return (1);
}
return (0);
}