In
#include <unistd.h>
int execve(const char * pathname , char *const argv [], char *const envp []);
argv [0]
of execve
corresponds to argv[0]
in the main function of the new program, and is thus typically the same as the basename component of the pathname
argument.
Is it a requirement that we should always follow?
When a program file can be invoked by different values of argv[0]
, does that rule/convention mean that when I invoke a program file and want argv[0]
of its main()
to have a specific value, I have to create a symlink to the program file named after the value of argv[0]
, and invoke the program by the symlink? Or not necessarily?
For example, this answer to “Why does argv include the program name?” says
Bash runs in POSIX mode when
argv[0]
issh
. It runs as a login shell whenargv[0]
begins with-
.
Does that mean that
to invoke bash in POSIX mode, I have to create a symlink
/path/to/sh
to/bin/bash
and invoke bash byexecve("/path/to/sh", argv, ...)
withargv[0]
pointing to string"sh"
? Is this way preferrable overexecve("/bin/bash", argv, ...)
whereargv[1]
points to string"--posix"
andargv[0]
doesn't matter?to invoke bash as a login shell, I have to create a symlink
/path/to/-
to/bin/bash
and invoke bash byexecve("/path/to/-", argv, ...)
withargv[0]
pointing to string"-"
? Is this way preferable overexecve("/bin/bash", argv, ...)
whereargv[1]
points to string"--login"
andargv[0]
doesn't matter?
When is it useful that argv [0]
of execve
is not the same as the basename component of the pathname
argument?
execve()
, so I don't know which way you're going with this question. – Jeff Schaller Nov 28 '18 at 18:59