How does the `execve()` system call differ from other exec calls when it comes to passing environment variables? Provide an example illustrating its use.
execve system call is the main call that runs in the background no matter whatever call you are running. It sets its own environment as well as argument strings. Here's how the syntax looks like:-
int execve(const char* path, char* const argv[], char* const envp[]);
Here argv is an array of argument variables, path is the pathname of the command we are looking for, while envp is the array of environment variables which are specified. A typical use-case would look as:-
char* argv = {"ls","-l",NULL};
char* envp = {"USER=guest","PATH=/tmp",NULL};
int execve("/bin/ls",argv,envp);
Here the system looks for ls in bin and looks for other argument variables specified in argv with envp as the environment.