Comparison of three functions of EXECV related execution files in C language _c language

Source: Internet
Author: User

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

 #include <unistd.h>

To define a function:

int EXECV (const char * path, char * const argv[]);

Function Description: The EXECV () is used to execute the path of the file represented by the parameter path string, unlike Execl () where the Execve () takes only two arguments, and the second parameter is passed to the execution file using an array pointer.

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: Refer to Execve ().

Example

/* Execute/BIN/LS-AL/ETC/PASSWD
/#include <unistd.h>
main ()
{
  char * argv[] = {"ls", "-al", "/etc/pa SSWD ", (char*)};
  EXECV ("/bin/ls", argv);
}

Perform:

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

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

 #include <unistd.h>

To define a function:

int Execve (const char * filename, char * const argv[], char * const envp[]);

Function Description: Execve () is used to execute the file path represented by the parameter filename string, and the second parameter is passed to the execution file using an array pointer, and the last parameter is an array of new environment variables passed to the execution file.

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:

Eacces:
1. The file to be executed does not have the permissions that the user can perform.
2. The file system to which the file is to be executed is hung in a noexec manner.
3. The file or script translator to be executed is not a general document.

Eperm:
1. The process is in the mode of being chased, the performer does not have root permission, the file to execute has suid or sgid bit.
2. The file system in which the file is to be executed is nosuid and the file to be executed has suid or sgid bits, but the performer does not have root permissions.

E2big parameter array is too large

Enoexec is unable to determine the execution file format of the file, possibly malformed or unable to execute on this platform.

Efault parameter filename refers to a string address that is outside the scope of the accessible space.

Enametoolong parameter filename refers to a string that is too long.

The file specified by the enoent parameter filename string does not exist.

Enomem Core memory is low

The Enotdir parameter filename string contains a directory path that is not a valid directory

The eacces parameter filename string contains a directory path that is not accessible and has insufficient permissions.

Eloop Too many symbolic connections

Etxtbusy the file you want to execute has been opened by another process and is writing data to the file

Eio I/O access errors

The Enfile has reached the total number of open files allowed by the system.

Emfile has reached the total number of files that the system allows a single process to open.

Einval to execute the file the elf execution format is more than just a pt_interp section area

Eisdir ELF Translator as a directory

There is a problem with the Elibbad ELF translator.

Example

#include <unistd.h>
Main ()
{
  char * argv[] = {"ls", "-al", "/etc/passwd", (char *) 0};
  char * envp[] = {"Path=/bin", 0};
  Execve ("/bin/ls", argv, ENVP);
}

Perform:

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

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

 #include <unistd.h>

To define a function:

int EXECVP (const char *file, char * const argv []);

Function Description: EXECVP () looks for the file name that matches the parameter file from the directory referred to in the PATH environment variable, executes the file when it is found, and then passes the second parameter argv to the executable file.

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: Refer to Execve ().

Example

/* Please check with EXECLP () sample/* *
#include <unistd.h>
main ()
{
  char * argv[] = {"ls", "-al", "/etc/passwd", 0};
  EXECVP ("ls", argv);
}

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.