我最近一直在学习一门系统编程课程,通过了系统调用exec()execve().到目前为止,我找不到这两者之间的任何区别,甚至维基百科也没有给出明确的解释,exec()execve()之间也有区别.

有人可以简单描述一下exec家族的系统调用,比如execl()execv()execle()execvp().

推荐答案

使用man exec并阅读:

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

所以你把一个数组作为参数传递

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

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

在这里:

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

您正在调用一个没有路径的文件,因此它希望您在调用之前已经处于正确的path位.

最后但并非最不重要:

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

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

Linux相关问答推荐

如何删除字符串中的`{{i:`and `}}`

c++进程状态中的+是什么意思

用于替换 struct 文档中文本的 Bash 脚本

如何使用 shell 脚本将文本文件转换为 JSON 文件

awk/sed 命令仅在模式 2 匹配时打印模式 1

如何安装脚本以从命令行的任何位置运行?

anon 对 pmap 意味着什么?

如何增加 /proc/pid/cmdline 4096 字节限制?

如何排除 tar 的绝对路径?

你如何在 C 中的 Linux 上进行非阻塞控制台 I/O?

SVN 错误:无法将字符串从本机编码转换为UTF-8

从linux命令行写入串口

bash 脚本中的自动 docker 登录

将原始数据发送到 TCP 服务器的 Linux 工具

根据文件名模式和文件内容列出文件名?

在 bash 中将输出作为 cp 的参数传递

是否有git sed或类似功能?

我可以使用 awk 将所有小写字母转换为大写吗?

`os.symlink` 与 `ln -s`

如何通过命令行识别特定的 Linux 风格?