Skip to content

Instantly share code, notes, and snippets.

@comex
Created June 17, 2023 00:25
Show Gist options
  • Save comex/0402dc95afb1c2ca3076d5b1b64bccc0 to your computer and use it in GitHub Desktop.
Save comex/0402dc95afb1c2ca3076d5b1b64bccc0 to your computer and use it in GitHub Desktop.
#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