exec函数族 整理笔记

2019-07-12 19:47发布

以ls -l为例 #include int execl(const char *path, const char *arg, ...); int execlp(const char *file, const char *arg, ...); int execl(const char *path, const char *arg, ..., char * const envp[]); int execv(const char *path, char *const argv[]); int execl(const char *file, char *const argv[]); int execl(const char *path, char *const argv[], char * const envp[]);
execl execl(“/bin/ls”, “ls”, “-l”, NULL);execlp 在上面的基础上去掉了ls的路径/bin/ execlp(“ls”, “ls”, “-l”, NULL);execv 把”ls”, “-1”, NULL这些命令行参数通过指针数组str传给exec函数 char *str[] = {“ls”, “-l”, NULL}; execv(“/bin/ls”, str);execvp  在上面的基础上去掉了ls的路径/bin/ char *str[] = {“ls”, “-l”, NULL}; execvp(“ls”, str);execle char *arrEnv[] = {“PATH=/bin:/usr/bin”, “TERM=console”, NULL}; execle(“/bin/ls”, “ls”, “-l”, NULL, arrEnv);execve char *str[] = {“ls”, “-l”, NULL}; char *arrEnv[] = {“PATH=/bin:/usr/bin”, “TERM=console”, NULL}; execve(“/bin/ls”, str, arrEnv);