Reputation: 33
Assume the following code in c:
#include <unistd.h>
#include <stdlib.h>
int main(int argc, char * argv[]) {
char *args[] = {"/bin/echo", "1", NULL};
execvp(args[0], args);
}
Why does execvp
accept 2 arguments? Why can't it be execvp(args)
and internally it would automatically grab the executable to run from args[0]
?
Upvotes: 3
Views: 287
Reputation: 409364
What if you want the "name" of the process (args[0]
in your case) to be different from the actual executable program? That is a valid use-case, and the simplest solution to handle both the cases is the two-argument execvp
we now have.
Upvotes: 3