This question is follow-up for this question.
When the bash command is issued by posix_spawn() I get the message:
bash: no job control in this shell
I think is because in the fork sequence there is call to the function setsid() and I don't know how to simulate this operation while using posix_spawn().
Is there a way to make new session for the bash process?
You can't. It's not part of the current
posix_spawninterface. Adding it has been discussed at http://austingroupbugs.net/view.php?id=1044 and apparently at least one implementation (QNX) providesPOSIX_SPAWN_SETSIDas an extension, but to stay standard compliant you need to usefork.Using
forkshouldn't be an issue if the parent process is small, so I imagine that to get the best of both worlds, you could useposix_spawnto launch a small helper binary thatforksand callssetsid. IMO, usingsetsidshould be rare enough for the small additional cost of double-execing to be negligible.