execlp 中文man页面

系统
exec 系列 函数 用 新的 进程 映象 置换 当前的 进程 映象. 本 手册页 描述的 这些 函数 实际上 是 对 execve(2) 函数 的 前端(front-end) 包装. (关于 当前进程 的 置换 详见 execve 的 手册页.)

NAME

execl, execlp, execle, execv, execvp - 执行某个文件

总览 (SYNOPSIS)

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

描述 (DESCRIPTION)

exec 系列 函数 用 新的 进程 映象 置换 当前的 进程 映象. 本 手册页 描述的 这些 函数 实际上 是 对 execve(2) 函数 的 前端(front-end) 包装. (关于 当前进程 的 置换 详见 execve 的 手册页.)

这些 函数 的 第一个 参数 是 待执行 程序 的 路径名(文件名).

在 函数 execl, execlp, 和 execle 中, const char *arg 以及 省略号 代表 的 参数 可被 视为 arg0, arg1, ..., argn. 他们 合起来 描述了 指向 null 结尾的 字符串 的 指针 列表, 即 执行程序 的参数列表. 作为 约定, 第一个 arg 参数 应该 指向 执行程序名 自身. 参数列表 必须NULL 指针 结束!

execvexecvp 函数 提供 指向 null 结尾的 字符串 的 指针数组 作为 新程序 的 参数列表. 作为 约定, 指针数组 中 第一个 元素 应该 指向 执行程序名 自身. 指针数组 必须NULL 指针 结束!

execle 函数 同时 说明了 执行进程 的 环境(environment), 他 在 NULL 指针 后面 要求 一个 附加参数, NULL 指针 用于 结束 参数列表, 或者说, argv 数组. 这个 附加参数 是 指向 null 结尾的 字符串 的 指针数组, 他 必须NULL 指针 结束! 其他 函数 从 当前进程 的 environ 外部变量 中 获取 新进程 的 环境.

某些 函数 有 特殊的 语义.

如果 提供的 文件名 中 不包含 斜杠符(/), 函数 execlpexecvp 将 同 shell 一样 搜索 执行文件. 搜索路径 由 环境变量 PATH 指定. 如果 该 变量 不存在, 则 使用 缺省路径 ``:/bin:/usr/bin''. 另外, 某些 错误 要 特殊处理.

如果 对 某个 文件 的 访问 遭到 拒绝 ( execve 返回 EACCES), 这些 函数 将 在 搜索路径 中 继续 寻找. 如果 没有 找到 符合的 文件, 他们 返回时 把 errno 置为 EACCES.

如果 无法 识别 文件首部 ( execve 返回 ENOEXEC), 这些 函数 将 以 文件名 作为 第一个 参数 调用 shell. (如果 这个 尝试 失败 就 不再 进行 搜索 了.)

返回值 (RETURN VALUE)

任何 exec 函数 返回 均 表明 发生了 错误. 返回值 是 -1, 全局变量 errno 指出 错误类型.

文件 (FILE)

/bin/sh

错误 (ERROR)

这些 函数 均可能 失败, errno 被 置为 库函数 execve(2) 设置的 各种 错误类型.

另见 (SEE ALSO)

sh(1), execve(2), fork(2), environ(5), ptrace(2)

#p#

NAME

execl, execlp, execle, execv, execvp - execute a file  

SYNOPSIS

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

DESCRIPTION

The exec family of functions replaces the current process image with a new process image. The functions described in this manual page are front-ends for the function execve(2). (See the manual page for execve for detailed information about the replacement of the current process.)

The initial argument for these functions is the pathname of a file which is to be executed.

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 file name associated with the file being executed. The list of arguments must be terminated by a NULL pointer.

The execv and execvp 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 file name associated with the file being executed. The array of pointers must be terminated by a NULL pointer.

The execle function also specifies the environment of the executed process by following the NULL pointer that terminates the list of arguments in the parameter list or the pointer to the argv array with an additional parameter. This additional parameter 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 current process.

Some of these functions have special semantics.

The functions execlp and execvp will duplicate the actions of the shell in searching for an executable file if the specified file name does not contain a slash (/) character. The search path is the path specified in the environment by the PATH variable. If this variable isn't specified, the default path ``:/bin:/usr/bin'' is used. In addition, certain errors are treated specially.

If permission is denied for a file (the attempted execve returned EACCES), these functions will continue searching the rest of the search path. If no other file is found, however, they will return with the global variable errno set to EACCES.

If the header of a file isn't recognized (the attempted execve returned ENOEXEC), these functions will execute the shell with the path of the file as its first argument. (If this attempt fails, no further searching is done.)  

RETURN VALUE

If any of the exec functions returns, an error will have occurred. The return value is -1, and the global variable errno will be set to indicate the error.  

FILES

/bin/sh  

ERRORS

All of these functions may fail and set errno for any of the errors specified for the library function execve(2).  

SEE ALSO

sh(1), execve(2), fork(2), environ(5), ptrace(2)  

责任编辑:韩亚珊 来源: CMPP.net
相关推荐

2011-08-24 16:48:36

man中文man

2011-08-15 10:21:09

man中文man

2011-08-11 16:11:49

at中文man

2011-08-25 10:21:56

man.conf中文man

2011-08-25 15:39:42

fcloseall中文man

2011-08-25 15:00:15

cfgetispeed中文man

2011-08-19 18:35:50

issue中文man

2011-08-25 17:03:51

pclose中文man

2011-08-25 17:40:25

setvbuf中文man

2011-08-23 14:21:16

poweroff中文man

2011-08-24 15:52:59

intro中文man

2011-08-23 13:40:31

2011-08-25 15:54:08

ferror中文man

2011-08-25 17:24:54

puts中文man

2011-08-25 18:34:55

ungetc中文man

2011-08-23 10:03:40

useradd中文man

2011-08-23 10:29:02

chpasswd中文man

2011-08-23 10:34:22

convertquot中文man

2011-08-23 15:39:34

rpmbuild中文man

2011-08-24 15:48:38

INSERT中文man
点赞
收藏

51CTO技术栈公众号