首页 > 解决方案 > posix_spawn 返回代码 14“错误地址”是什么意思?

问题描述

我正在从我的应用程序中生成一个子进程:

    QString strFullPath(strModulesPath 
                      + strModule.toString());
    QByteArray baFullPath(strFullPath.toLatin1())
              ,baSeconds((QString::number(lngSeconds))
                       .toLatin1());
    char** ppEnviron
        ,* pszFullPath = baFullPath.data()
        ,* pszSeconds = baSeconds.data()
        ,* paryszArgs[] = {pszFullPath
                          ,pszSeconds
                          ,nullptr};
    posix_spawn_file_actions_t* pfileActionsp;
    posix_spawnattr_t* pAttr;
    pid_t pid = 0;
    pfileActionsp = pAttr = nullptr;
    int intRC = posix_spawn(&pid
                           ,pszFullPath
                           ,pfileActionsp
                           ,pAttr
                           ,paryszArgs
                           ,ppEnviron);

要启动的应用程序在 baFullPath 中指定并包含:

~/XMLMPAM/config/modules/mdFileIO

调用 posix_spawn 后返回的 pid 有效,intRC 返回 2。

但是我看不到“活动监视器”中列出的进程,列出了父进程但没有列出子进程。

它在哪里以及如何查看控制台的输出,因为它没有出现在与父进程相同的控制台中。

[编辑] 似乎“posix_spawn”不支持使用路径前缀“~”生成,所以我尝试了完整路径:

/Users/Simon/XMLMPAM/config/modules

我在调试器中查看,现在返回 14,根据错误列表,它是“错误地址”。

[编辑 2] 正如 David Schwartz 所指出的,它不起作用,因为我没有初始化“ppEnviron”。

标签: posix

解决方案


“David Schwartz”在对该问题的评论中指出了该问题的解决方案。

生成操作失败,因为指向环境的指针未初始化为 NULL。


推荐阅读