forked from ari1008/mini-shell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshellexecvp.c
48 lines (36 loc) · 974 Bytes
/
shellexecvp.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
// base pour faire SON shell ;p
// gcc -g -Wall -Wextra -fanalyzer -pedantic mini-shell.c -o mini-shell
#include <stdlib.h> // EXIT_SUCCESS
#include <stdio.h> // printf
#include <string.h>
#include <sys/wait.h> // wait
#include <sys/types.h> // pid_t
#include <unistd.h> // fork
int main(int argc, char *argv[])
{
pid_t pid;
int status;
//const char * separators = " ,.!"
printf("My pid : %d\n",getpid());
//si il y a un argument
if (argc > 1 )
{
if ((pid = fork())== -1)
{
perror("fork");
return EXIT_FAILURE;
}
//si pid = 0 alors on est dans le process fils
else if (pid == 0)
{
if (execvp(arg[1],argv + 1)== -1)
perror("execvp");
return EXIT_FAILURE; //on termine le fils meme si execve fail
}
//dans le pere
else
wait(&status);
}
//getchar();
return EXIT_SUCCESS;
}