forked from alzheimeer/shell_v2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecuting.c
More file actions
50 lines (47 loc) · 983 Bytes
/
Copy pathexecuting.c
File metadata and controls
50 lines (47 loc) · 983 Bytes
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
#include "hsh.h"
/**
* executing - execute function.
* @info: structur
* Return: none
*/
void executing(info_t *info)
{
pid_t pid;
pid = fork();
if (pid == -1)
{
perror("Error:");
return;
}
if (pid == 0)
{
if (info->read_inPipe == 1)
{
dup2(info->pipefd[READ], STDIN_FILENO);
close(info->pipefd[READ]);
}
if (info->write_inPipe == 1)
{
close(info->pipefd[READ]); /* cerrar extremo no necesario */
dup2(info->pipefd[WRITE], STDOUT_FILENO);
close(info->pipefd[WRITE]);
}
if (execve(info->path, info->tokens, environ) == -1)
{
print_error(info, "not found");
if (errno == EACCES)
exit(126);
exit(1);
}
}
else
{
if (info->read_inPipe == 1)
close(info->pipefd[READ]); /* extremo no necesario ya */
if (info->write_inPipe == 1)
close(info->pipefd[WRITE]); /* extremo no necesario ya */
}
do {
waitpid(pid, &(info->status), WUNTRACED);
} while (!WIFEXITED((info->status)) && !WIFSIGNALED((info->status)));
}