exec function family for process control in Linux

Source: Internet
Author: User

1. Introduction

In Linux, there is no exec () function, exec refers to a set of functions, a total of 6, respectively:

#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[]);

Detailed definition:

EXECL (execution file)

Related functions

Fork,execle,execlp,execv,execve,execvp

Table header File

#include <unistd.h>

Defining functions

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 ..., and the last argument must end with a null pointer (NULL).

return value

If the execution succeeds, the function does not return, and the execution failure returns 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

EXECLP (find files from the PATH environment variable and execute)

Related functions

Fork,execl,execle,execv,execve,execvp

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.