I'm spawning a child process from my application:
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);
The application to launch is specified in baFullPath and contains:
~/XMLMPAM/config/modules/mdFileIO
The pid returned after the call to posix_spawn is valid and intRC returns 2.
However I cannot see the process listed in the "Activity Monitor", the parent process is listed but not the child.
Where is it and how can I see the output from the console as it doesn't appear in the same console as the parent process.
[edit] It would appear that the "posix_spawn" doesn't support spawning using the path prefix "~", so I tried the full path:
/Users/Simon/XMLMPAM/config/modules
I watched in the debugger and now the return is 14, which according to the error list is "Bad Address".
[edit 2] As pointed out by David Schwartz, it wasn't working because I hadn't initialised the "ppEnviron".
The solution to this problem was pointed out by "David Schwartz" in a comment to the question.
The spawn operation was failing because the pointer to the environment wasn't initialised to NULL.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With