exec函数簇

函数声明

  • 包含头文件
    #include <unistd.h>
  1. execl
    int execl(const char *path, const char *arg, ... /* (char *)NULL */);
  2. execlp
    int execlp(const char *file, const char *arg, ... /* (char *)NULL */);
  3. execle
    int execle(const char *path, const char *arg, ... /* (char *)NULL , char *const envp[] */);
  4. execv
    int execv(const char *path, char *const argv[]);
  5. execvp
    int execvp(const char *file, char *const argv[]);
  6. execvpe
    int execvpe(const char *file, char *const argv[], char *const envp[]);

函数特性

/************************List*************************/

- execl()、execlp()、execle()

The const char *arg and subsequent ellipses in the execl(), execlp(), and execle() functions can be thought of as arg0, arg1, … , argn. Together they describe a list of one or more pointers to null-terminated strings that represent the argument list available to the executed program. The first argument, by convention, should point to the filename associated with the file being executed. The list of arguments must be terminated by a null pointer, and, since these are variadic functions, this pointer must be cast (char *) NULL.

/***********************Vector************************/

- execv()、execvp()、execvpe()

The execv(), execvp(), and execvpe() functions provide an array of pointers to null-terminated strings that represent the argument list available to the new program. The first argument, by convention, should point to the filename associated with the file being executed. The array of pointers must be terminated by a null pointer.

/*******************environment***********************/

- execle()、execvpe()

The execle() and execvpe() functions allow the caller to specify the environment of the executed program via the argument envp. The envp argument is an array of pointers to null-terminated strings and must be terminated by a null pointer. The other functions take the environment for the new process image from the external variable environ in the calling process.

/***********************filename**********************/

- execlp()、execvp()、execvpe()

The execlp(), execvp(), and execvpe() functions duplicate the actions of the shell in searching for an executable file if the specified file name does not contain a slash (/) character. * The file is sought in the colon-separated list of directory pathnames specified in the PATH environment variable*. If this variable isn’t defined, the path list defaults to the current directory followed by the list of directories returned by confstr(_CS_PATH). (This confstr(3) call typically returns the value “/bin:/usr/bin”.)
If the specified filename includes a slash character, then PATH is ignored, and the file at the specified pathname is executed.
In addition, certain errors are treated specially. If permission is denied for a file (the attempted execve(2) failed with the error EACCES), these functions will continue searching the rest of the search path. If no other file is found, however, they will return with errno set to EACCES. If the header of a file isn’t recognized (the attempted execve(2) failed with the error ENOEXEC), these functions will execute the shell (/bin/sh) with the path of the file as its first argument. (If this attempt fails, no further searching is done.)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值