-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecuting_program.c
More file actions
57 lines (51 loc) · 808 Bytes
/
executing_program.c
File metadata and controls
57 lines (51 loc) · 808 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
51
52
53
54
55
56
57
#include "main.h"
/**
* execute_cmd - execute command
* @argv: array of strings
* Return: void
*/
void *execute_cmd(char **argv)
{
char *line = NULL, *ret_line = NULL;
if (!argv)
{
return (NULL);
}
line = argv[0];
ret_line = get_path(line);
if (!ret_line)
{
free(line);
return (NULL);
}
if (execve(ret_line, argv, NULL) == -1)
{
perror("execve");
}
free(ret_line);
return (NULL);
}
/**
* forking - to create a child for the process
* @new_argv: string represent the command
* Return: int value represents the id of child process
*/
int forking(char **new_argv)
{
pid_t child_process = fork();
int status = 0;
if (child_process == -1)
{
return (-1);
}
if (child_process == 0)
{
execute_cmd(new_argv);
return (-1);
}
else
{
wait(&status);
}
return (0);
}