
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include <unistd.h>
#include <spawn.h>
#include <sys/wait.h>

extern char **environ;


int main(void) {
    char *argv[] = {"/bin/true", NULL};
    int status;
    pid_t pid;
    posix_spawnattr_t attr;


    posix_spawnattr_init(&attr);
    posix_spawnattr_setflags(&attr, POSIX_SPAWN_RESETIDS);

    status = posix_spawn(&pid, "/bin/true",
                         NULL, &attr, argv, environ);
    if (status == 0) {
        if (waitpid(pid, &status, 0) != -1) {
            printf("Child exited with status %i\n", status);
        } else {
            perror("waitpid");
        }
    } else {
        printf("posix_spawn: %s\n", strerror(status));
    }
    posix_spawnattr_destroy(&attr);
    return 1;
}
