exec系列系统调用(例如exec和execve)的功能之间有什么区别? [英] What is the difference between the functions of the exec family of system calls like exec and execve?

查看:181
本文介绍了exec系列系统调用(例如exec和execve)的功能之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近一直在学习系统编程课程,并且遇到了系统调用 exec() execve().到目前为止,我找不到这两者之间的任何区别,即使Wikipedia也没有给出明确的解释,所以 exec() execve()之间也存在区别.

I have been following a system programming course recently and I came through the system calls exec() and execve(). So far I cannot find any difference between these two, Even the Wikipedia does not give a clear explanation, so is there a difference between exec() and execve().

请有人可以提供有关exec系列系统调用的简短说明,例如 execl() execv() execle() execvp().

And someone please could give brief descriptions about exec family system calls such as execl(), execv(), execle(), execvp().

推荐答案

使用 man exec 并阅读:

Use man exec and read:

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. 

execv

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

因此您将数组作为参数传递

So you pass an array as parameters

int execle(const char *path, const char *arg,
              ..., char * const envp[]);

几乎相同,但不是一个数组,而是一个值列表(字符串),后面跟着一个数组来指定环境.

Almost the same, but not as an array, but rather as a list of values (strings), followed by an array the designates the environment.

这里:

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

您正在调用的文件没有路径,因此它希望您在调用前已经在正确的path中.

You are calling a file, without path, so it expects you to be already in the right path before calling.

最后但并非最不重要:

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

类似于上一个,但是现在有两个数组,用于参数和环境变量.

Similar to previous one, but now you have two arrays, for arguments and environment variables.

这篇关于exec系列系统调用(例如exec和execve)的功能之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆