#include"apue.h"
#include"sys/wait.h"
#include"myerr.h"
int main()
{
pid_t pid;
if((pid = fork()) < 0)
{
err_sys("fork error!\n");
}
else if(pid == 0)
{
if(execl("/Ad_Pro_in_Unix/chapter_8/testinterp","testinterp",NULL) < 0)
{
err_sys("execl error!\n");
}
}
if(waitpid(pid,NULL,0) < 0)
{
err_sys("waitpid error!\n");
}
exit(0);
}
注意execl的第一个参数指向的文件必须是executable file
"/Ad_Pro_in_Unix/chapter_8/testinterp"
查看testinterp文件的属性
-rw-rw-r-- 1 liuzjian liuzjian 10 1月 29 23:50 testinterp
发现问题是该文件不具有可执行的权限,于是改变文件属性,使之具有可执行权限,在此运行程序即可
一句话搞定:
The initial argument for these functions is the pathname of a file which is to be executed.