execl error permission denied ——apue figure8-20 遇到的问题

本文介绍了一个关于使用execl函数执行文件时遇到的权限问题,并详细解释了解决方案,即通过更改文件属性以赋予其可执行权限。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值