c - execvp 在 c 中返回权限被拒绝的错误

标签 c permissions fork exec

我想编写一个使用 exec 的程序来改变一个 child 并用它来做窗帘 Action 。 child 必须计算一个简单的等式 (-,+,*,/)。 当我尝试使用 execvp 访问文件时,出现以下错误:

execvp() failed!: Permission denied

有人知道我做错了什么吗? 下面是我的代码。

int main()
{
    signal(SIGCHLD, SIG_IGN);   //ignore child signal from now on
    pid_t status;
    char *a[2] = { "calculator", "2+1", NULL };

    status = fork();
    if (status != 0)
    {
        do_child(0, a);
    }


    return EXIT_SUCCESS;
}

/*
 *  id 0: calculator
 *  id 1: factorial
 *  id 2: pid
 */

 void do_child(int id, const char *args[])
 {
    switch (id) {
    case 0:
        if (execvp("../ex2cFactorial/ex2cCalculator.c", args) != 0)
        {
            perror("execvp() failed!");
            exit(EXIT_FAILURE);
        }
        break;
        //other cases (haven't been written yet)
    }
 }

最佳答案

ex2cCalculator.c 可能是一个源文件,您需要的是可执行文件的名称(ex2cCalculatora.out随便)

数组初始化器中也有多余的元素。它应该是 char *a[3] = { "calculator", "2+1", NULL };

关于c - execvp 在 c 中返回权限被拒绝的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40973906/

相关文章:

C 包含库失败

c - 而不是打印二进制数,我如何将它存储为变量?

php - Facebook - 如何使用 iframe 应用程序直接进入请求权限对话框?

c++ - 如果花费太多时间,则终止子进程

Linux Kernel NUMA相关变量在struct task_struct中

c - parent 从文件中读取操作, child 将其与 bc 相加

arrays - 数组如何存储在堆栈中?

python - 自定义大小数组

linux - 嵌入式应用程序应该以哪个用户身份运行?

svn - 颠覆阻止使用 SVNParentPath 在文件夹中列出存储库