exec函数

当进程调用一种exec函数时,该进程执行的程序完全替换为新程序,新程序从main函数开始执行,调用exec并不创建新进程,所以前后的进程ID并未改变。exec只是用磁盘上的一个新程序替换当前进程的正文段、数据段、堆和栈。

#include <unistd.h>
int execl(const char *pathname, const char *arg0, ...);
int execv(const char *pathname, char *const argv[]);
int execle(const char *pathname, const char *arg0, ...,char *const envp[]);
int execve(const char *pathname, char *const argv[], char *const envp[]);
int execlp(const char *filename, const char *arg0, ..);
int execvp(const char *filename, char *const argv[]);
int fexecve(int fd, char *const argv[], char *const envp[]);

出错返回-1,成功不返回

前4个函数以路径名作为参数,后2个以文件名作为参数,最后一个以文件描述符作为参数。


猜你喜欢

转载自blog.csdn.net/aabb7012086/article/details/80715353