Why first arg to execve() must be path to executable
Posted
by EBM
on Stack Overflow
See other posts from Stack Overflow
or by EBM
Published on 2010-06-12T03:08:28Z
Indexed on
2010/06/12
3:12 UTC
Read the original article
Hit count: 261
I understand that execve() and family require the first argument of its argument array to be the same as the executable that is also pointed to by its first argument. That is, in this:
execve(prog, args, env);
args[0] will usually be the same as prog. But I can't seem to find information as to why this is.
I also understand that executables (er, at least shell scripts) always have their calling path as the first argument when running, but I would think that the shell would do the work to put it there, and execve() would just call the executable using the path given in its first argument ("prog" from above), then passing the argument array ("args" from above) as one would on the command line.... i.e., I don't call scripts on the command line with a duplicate executable path in the args list....
/bin/ls /bin/ls /home/john
Can someone explain?
© Stack Overflow or respective owner