The exec function group has six functions:
# Include <unistd. h>
Extern char ** environ;
Int execl (const char * path, const char * Arg ,...);
Int execlp (const char * file, const char * Arg ,...);
Int execle (const char * path, const char * Arg,..., char * const envp []);
Int execv (const char * path, char * const argv []);
Int execvp (const char * file, char * const argv []);
Int execve (const char * path, char * const argv [], char * const envp []);
These six functions can be distinguished as follows:
1. Parameters with L are given in the form of list, that is, each parameter is separated by a comma. Multiple parameters are given to multiple strings.
2. The expression parameter with V is given in vector mode, that is, a string array pointer.
3. An external command with P can be written as a relative path, and the function will search for it in the PATH environment variable.
4. Environment variables can be customized with E.
OK. Now it is clear that if we want the called command to inherit the context of the caller's environment variable, execv, execvp can be used; if a function such as execve is used, pay attention to the third parameter, that is, the list of environment variables cannot be null. If it is null, the called command cannot get the caller's list of environment variables. If you want to use a function such as execve, you must first save the current environment variable and then add the custom environment variable, put it on the third parameter.