forked from RicardoArquimedes/simple_shell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_fork_function.c
More file actions
41 lines (37 loc) · 757 Bytes
/
_fork_function.c
File metadata and controls
41 lines (37 loc) · 757 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
#include "shell.h"
/**
* _fork_fun - function that create a fork
*@arg: command and values path
*@av: Has the name of our program
*@env: environment
*@lineptr: command line for the user
*@np: id of proces
*@c: Checker add new test
*Return: 0 success
*/
int _fork_fun(char **arg, char **av, char **env, char *lineptr, int np, int c)
{
pid_t child;
int status;
char *format = "%s: %d: %s: not found\n";
child = fork();
if (child == 0)
{
if (execve(arg[0], arg, env) == -1)
{
fprintf(stderr, format, av[0], np, arg[0]);
if (!c)
free(arg[0]);
free(arg);
free(lineptr);
exit(errno);
}
}
else
{
wait(&status);
if (WIFEXITED(status) && WEXITSTATUS(status) != 0)
return (WEXITSTATUS(status));
}
return (0);
}