Simple comparison of execl () function and EXECLP () function _c language in C language

Source: Internet
Author: User

C language Execl () function: Performing file functions
header file:

#include <unistd.h>

To define a function:

int execl (const char * path, const char * arg, ...);

Function Description: The EXECL () is used to execute the path of the file represented by the parameter path string, and the next argument represents the passing of the past argv (0), argv[1] When the file is executed, the last argument must end with a null pointer (NULL).

Return value: If the execution succeeds then the function does not return, the execution fails to return 1 directly, and the reason for failure is in errno.

Example

#include <unistd.h>
Main ()
{
  execl ("/bin/ls", "ls", "-al", "/etc/passwd", (char *) 0);

Perform:

/* Execute/BIN/LS-AL/ETC/PASSWD */
-rw-r--r--1 root 705 Sep 3 13:52/etc/passwd

C language EXECLP () function: Find files from the PATH environment variable and execute
header file:

#include <unistd.h>

To define a function:

int EXECLP (const char * file, const char * arg, ...);

Function Description: EXECLP () looks up the filename of the parameter file from the directory referred to in the PATH environment variable, executes the file after it is found, and then takes the second parameter as the argv[0 of the file, Argv[1], ..., the last argument must have a null pointer (NULL) End.

Return value: If the execution succeeds then the function does not return, the execution fails to return 1 directly, and the reason for failure is in errno.

Error code: Reference Execve ().

Example

/* Execution ls-al/etc/passwd EXECLP () will find/bin/ls/
#include <unistd.h>
main ()
{
  EXECLP according to the/bin in the PATH variable ("ls", "ls", "-al", "/etc/passwd", (char *) 0);
}

Perform:

-rw-r--r--1 root 705 Sep 3 13:52/etc/passwd

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.