Mercurial > dnft
comparison spawn.cpp @ 0:4171b2d4684b default tip
initial commit
| author | Yasuri <linuxoverwindows@charliesmp.net> |
|---|---|
| date | Sat, 05 Sep 2026 15:35:48 -0500 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:4171b2d4684b |
|---|---|
| 1 #include <iostream> | |
| 2 #include <unistd.h> | |
| 3 #include <sys/wait.h> | |
| 4 #include <spawn.h> | |
| 5 extern char** environ; // idk what this does | |
| 6 int spawn(char* const argv[], const char* path) | |
| 7 { | |
| 8 pid_t pid; | |
| 9 int status; | |
| 10 status = posix_spawn(&pid, path, NULL, NULL, const_cast<char* const*>(argv), environ); | |
| 11 if (status != 0) { | |
| 12 std::cerr << "posix_spawn failed:" << strerror(status) << std::endl; | |
| 13 return 1; | |
| 14 } | |
| 15 if (waitpid(pid, &status, 0) == -1) { | |
| 16 perror("waitpid"); | |
| 17 return 1; | |
| 18 } | |
| 19 if (WIFEXITED(status)) { | |
| 20 return WEXITSTATUS(status); | |
| 21 } | |
| 22 return 1; | |
| 23 } |
