posix_spawn return 代码 14 "Bad Address" 是什么意思?

What does posix_spawn return code 14 "Bad Address" mean?

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

    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 return有效且intRC returns 2.

但是我看不到 "Activity Monitor" 中列出的进程,列出了父进程但没有列出子进程。

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

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

/Users/Simon/XMLMPAM/config/modules

我在调试器中观察,现在 return 是 14,根据错误列表是 "Bad Address"。

[edit 2] 正如 David Schwartz 所指出的,它没有工作,因为我没有初始化 "ppEnviron"。

EFAULT (14) 表示您传递的参数之一是无效地址。通常你可以在传递它们之前打印所有指针以确保它们指向有效内存。

这一行尤其可疑:

pfileActionsp = pAttr = nullptr;

man page 说:

The attrp argument points to an attributes objects that specifies various attributes of the created child process. This object is initialized and populated before the posix_spawn() call using posix_spawnattr_init(3) and the posix_spawnattr_*() functions.

"David Schwartz" 在对问题的评论中指出了此问题的解决方案。

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