-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexectest.c
More file actions
32 lines (27 loc) · 749 Bytes
/
Copy pathexectest.c
File metadata and controls
32 lines (27 loc) · 749 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
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
/**
* main - a test function
* @argc: argument count
* @argv: argument vector
*
* Return: always 0
*/
int main(int argc, char **argv)
{
char *Arglist[] = { NULL, "echo", "testing", NULL};
char **Env = { NULL };
if (argc > 2)
{
fprintf(stderr, "Agr count shouldnt be more than 2");
exit(EXIT_FAILURE);
}
Arglist[0] = argv[1];
execve(argv[1], Arglist, Env);
perror("execve failed");
exit(EXIT_SUCCESS);
}
/** This code alway work the same way has execve.c
* since the first parameter is argv[1], it will alway run whatever compiled file that fall to index(1).
* Same thing also happened in execp.c file, ot only ran the what was in arglist[0] and then things in arglist */