Usage and difference of the six functions in the exec function group

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.