Created
June 17, 2023 00:25
-
-
Save comex/0402dc95afb1c2ca3076d5b1b64bccc0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <spawn.h> | |
#include <assert.h> | |
#include <stdlib.h> | |
#include <sys/wait.h> | |
#include <stdio.h> | |
extern char **environ; | |
int main(int argc, char **argv) { | |
if (!argv[1]) { | |
fprintf(stderr, "usage: spawn-bench <command> [args...]\n"); | |
return 1; | |
} | |
char *path = argv[1]; | |
for (int i = 0; i < 1000; i++) { | |
pid_t pid; | |
assert(!posix_spawn(&pid, argv[1], NULL, NULL, argv + 1, environ)); | |
int st; | |
assert(pid == waitpid(pid, &st, 0)); | |
assert(WIFEXITED(st)); | |
assert(WEXITSTATUS(st) == 0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment