-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path_fork.c
More file actions
39 lines (37 loc) · 678 Bytes
/
_fork.c
File metadata and controls
39 lines (37 loc) · 678 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
#include "main.h"
/**
* _fork - Forks a child process and executes a command in it
* @argc: The argument count
* @argv: The argument vector
* @buf: The command buffer
* @ave: The argument vector for execve
* @only: The command to execute
* @status: status to exit
*/
void _fork(int argc, char *argv[], char *buf, char *ave[],
char *only, int *status)
{
signed int pid;
(void)argv;
(void)argc;
pid = fork();
if (pid == -1)
{
perror("Failed to fork");
free(buf);
exit(EXIT_FAILURE);
}
if (pid == 0)
{
/*ls_check(ave, buf, only);*/
execve(ave[0], ave, environ);
perror("execve fail");
free(buf);
free(only);
exit(1);
}
else
{
wait(status);
}
}