我最近一直在学习一门系统编程课程,通过了系统调用exec()和execve().到目前为止,我找不到这两者之间的任何区别,甚至维基百科也没有给出明确的解释,exec()和execve()之间也有区别.
有人可以简单描述一下exec家族的系统调用,比如execl()、execv()、execle()、execvp().
我最近一直在学习一门系统编程课程,通过了系统调用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[]);
与前一个类似,但现在有两个数组,用于参数和环境变量.