海风游戏狂欢季-独家活动首发平台

exec函数族解析
2026-08-18 02:59:45

1.首先解释一下,exec函数的作用:它是为了在一个程序中运行另一个程序。

例如:在一个程序中,执行fork(),可以产生两个进程,我们可以通过exec函数族来实现对父子进程的执行程序进行改变。

2.exec函数族

#include

extern char **environ;

int execl(const char *path,const char *arg, ...); //带有可变参数的需在参数列表之后添加NULL。

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 *file,char *const argv[],char *const envp[]);

3.exec函数族中后缀l、p、e、v分别表示的含义

后缀

含义

l(list)

命令行参数

p(path)

搜索file时用path变量

v(vector)

使用命令参数数组

e(environment)

使用环境变量数组,不使用进程原有的环境变量,设置新加载程序运行的环境变量

eg: execlp("ls”, ”ls”, ”-l”, ”-a”, NULL);

execl("/bin/ls”, ”ls”, ”-l”, ”-a”, NULL);

区别:需要添加路径。

4.函数返回值

函数执行成功,不进行返回值;执行错误,返回-1.

我眼里的BMW E46。18年购入使用3年用车感受。
洛杉矶改革宗·恩约教会
最新文章