-
Notifications
You must be signed in to change notification settings - Fork 0
/
execute.c
53 lines (52 loc) · 858 Bytes
/
execute.c
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
#include "shell.h"
/**
*execute - executing the command
*@input: array of command
*@buff: string of the command
*@fpathbuff: string of the path
*Return: 0 on succes
*/
int execute(char **input, char *buff, char *fpathbuff)
{
int i, stat, ex, exitv = 0;
pid_t pid;
pid = fork();
if (pid == -1)
{
perror("Error");
exit(1);
}
if (pid == 0)
{
ex = execve(fpathbuff, input, environ);
if (ex == -1)
{
perror(input[0]);
for (i = 0; input[i]; i++)
free(input[i]);
free(input);
free(buff);
exit(127);
}
}
wait(&stat);
if (WIFEXITED(stat))
exitv = WEXITSTATUS(stat);
for (i = 0; input[i]; i++)
free(input[i]);
free(input);
free(buff);
return (exitv);
}
/**
* signal_to_handel - Handle ^C
* @sig:Captured Signal
* Return: Void
*/
void signal_to_handel(int sig)
{
if (sig == SIGINT)
{
write(1, "\n$ ", 3);
}
}