Hello everyone
I have an example code:
pid = fork(); if (pid == 0) { execvp(argv[2],&argv[2]); perror("Error"); }else { wait(NULL); }
Of man execI understand that
man exec
"The first argument, by convention, must point to the file name associated with the executable."
So, if I executed my program as follows:
./a.out 5 ls
The ls command will be executed.
What about the second argument? the manual says
"The array of pointers must be interrupted by a NULL pointer"
and I donβt see the NULL pointer here, and I donβt understand what is a function here &argv[2].
&argv[2]
Many thanks!
execvp - char*, argv. execvp , , "" NULL, , {"foo", "bar"} argv, execvp {"foo", "bar", NULL}. , argv, main, NULL, &argv[2] execvp , NULL .
execvp
char*
argv
NULL
{"foo", "bar"}
{"foo", "bar", NULL}
main
a.out, , , main :
int main(int argc, char *argv[]) /* argv contains this. */ argv[0] == "a.out" argv[1] == "5" argv[2] == "ls" argv[3] == NULL /* Here is your terminator. */
, argv[2] execvp, , 2 ( ls).
argv[2]
ls