-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_fork.c
More file actions
44 lines (41 loc) · 736 Bytes
/
_fork.c
File metadata and controls
44 lines (41 loc) · 736 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
#include "sshell.h"
/**
* _fork - program that creates process and execute
* @p: array of pointer (args)
* @l: input typed by the user
* @a: count of pointers
* @L: count of loops
* @v: arguments in input
* @e: env length
* @m: copy of environmental variable
* @f: complete input
* Return: Nothing.
*/
void _fork(char **p, char *l, int a, int L, char **v, int e, char **m, char *f)
{
pid_t child_pid;
int status;
child_pid = fork();
if (child_pid == -1)
{
perror("Error");
exit(127);
}
if (child_pid == 0)
{
if (execve(p[0], p, m) == -1)
{
_put_err(p, L, 3, v);
}
free(f);
free(l);
gridfree(p, a);
gridfree(m, e);
/*printf("After execve\n");*/
exit(127);
}
else
{
wait(&status);
}
}