Exec
This is a family of functions
One system call
A bunch of library calls.
exec*
A
v
means the arguments are vector
A
e
means that the environment is specified (not the default environment)
A
l
means arguments are in long form
A
p
means the path is searched.
Unless the path begins with a /
exec
ve
is an exec where
the arguments are given in vector form,
the environment is specified (not inherited from the parent),
the path is not searched.
execve
This is the system call
int execve(const char *filename, char *const argv[], char *const envp[]);
The filename is the file to execute.
It must be either an absolute or relative path.
The environment variable PATH will not be searched.
And no ~ expansion.
It must be marked as executable.
This can be a binary executable (from a compiler)
Or a script for an interpreter.
If it is a binary, the appropriate loader is called.
If it is a script
The first line must be in the form
#!/path/to/interpreter [optional arguments]
argv is a null terminated list of arguments.
argv[0] by
convention
is the name of the program.
By convention it does not include the path.
The function
basename
might be helpful here
char *dirname(char *path);
Needs libgen.h
This might modify the string, so send in a copy
envp is a null terminated list of environment variables.
The function returns -1 on failure
It will never return on success.
You should read the book/manpage for things that happen on exec
For the most part, the general environment (not environment variables) is cleaned up.
But files are left open (unless otherwise specified)
look at
blabber.C
blabber.sh
runner.C
runner blabber a b c
runner blabber.sh a b c
runner /usr/bin/echo a b c
runner `pwd`/blabber a b c
There are a bunch of library equivalents
See man 3 exec.