相关函数:fork, execle, execlp, execv, execve, execvp
表头文件:#include <unistd.h>
函数定义:int execl(const char *path, const char *arg, ...);
函数说明:execl()用来执行参数path字符串所代表的文件路径, 接下来的参数代表执行该文件时传递的argv[0],argv[1].....是后一个参数必须用空指针NULL作结束
返回值 :成功则不返回值, 失败返回-1, 失败原因存于errno中
错误代码:参execve()
范例:
/* 执行 /bin/ls -al /ect/passwd */
#include <unistd.h>
/**
* File: execl.c
*
*/
main()
{
execl("/bin/ls", "ls", "-al", "/etc/passwd", (char *) 0);
}
或
#include <unistd.h>
/**
* File: execl.c
*
*/
int main()
{
char args[]=" -l";
execl("/bin/ls","ls","-al","/etc/",NULL);
return 0;
}
[cnscn@test c]$
make execl
cc execl.c -o execl
[cnscn@test c]$
./execl
-rw-r--r-- 1 root root 2218 Jan 13 11:36 /etc/passwd