I am writing a program in C that forks and uses execv to call a command that is passed in to the original function.
So I would type in something like "./program echo "hello"" and the child of the fork in my program would use the bash command "echo hello".
The execv man page is pretty vague, it says "The first argument, by convention, should point to the filename associated with the file being executed." I am trying to figure out if I'm understanding this right.
From examples I've seen, this is how execv should be called:
execv(argv[0], argv);
But I know that argv[0] would just contain "./program". So I am thinking this just exec's to the same function its inside of, but it is not what I've seen in examples.
From what I know it should be this:
execv(argv[1],argv+1);
or
execv(argv[1],argv+2);
Can anyone help me understand this? Thanks.