Put this in Base/home/anon/spawn.cpp, then run ninja image && ninja run
, and then in Serenity run gcc spawn.cpp && ./a.out
. The program doesn't wait() for its child that's running in a new process group.
Somehow, the Shell never gets control back. On Linux, this works fine.
I don't know what correct behavior is though, maybe hanging like this is fine.
#include <errno.h>
#include <spawn.h>
#include <stdio.h>
#include <unistd.h>
int main()
{
posix_spawnattr_t attr;
if ((errno = posix_spawnattr_init(&attr)) != 0) {
perror("posix_spawnattr_init:");
return 1;
}
if ((errno =posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSIGMASK)) != 0) {
perror("posix_spawnattr_init:");
return 1;
}
const char* argv[] = { "sh", "-c", "ls", nullptr };
pid_t child_pid;
if ((errno = posix_spawn(&child_pid, "/bin/sh", nullptr, &attr, const_cast<char**>(argv), environ)) != 0) {
perror("posix_spawn");
return 1;
}
if ((errno = posix_spawnattr_destroy(&attr) != 0) {
perror("posix_spawnattr_destroy");
return 1;
}
}
If I add this to the bottom (and includes for sys/types.h and sys/wait.h at the top), everything's fine:
int wstatus;
if (waitpid(child_pid, &wstatus, 0) < 0) {
perror("waitpid");
return 1;
}
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too