// simple example of posix_spawn // ./spawn_cat f.txt // The child will run /usr/bin/cat #include #include #include #include #include #include #include int main(int argc, char *argv[]) { pid_t pid; extern char **environ; if (argc < 2) { fprintf(stderr, "Usage: %s \n", argv[0]); return 1; } //TODO char *cat_argv[] = {"/usr/bin/cat",argv[1], NULL}; //TODO int ret = posix_spawn(&pid, "/usr/bin/cat", NULL, NULL, cat_argv, environ); if (ret != 0) { errno = ret; perror("spawn"); return 1; } int exit_status; if (waitpid(pid, &exit_status, 0) == -1) { perror("waitpid"); return 1; } printf("/bin/cat exit status was %d\n", exit_status); return 0; }