ZSH wait() syscall test bench for #BashOnUbuntuOnWindows. See https://github.com/Microsoft/BashOnWindows/issues/91#issuecomment-208077623
#include <sys/types.h> | |
#include <sys/time.h> | |
#include <sys/resource.h> | |
#include <sys/wait.h> | |
#include <stdio.h> | |
#include <errno.h> | |
int main() { | |
pid_t pid; | |
int status; | |
#define WAITFLAGS (WNOHANG|WUNTRACED|WCONTINUED) | |
#ifdef HAVE_WAIT3 | |
# ifdef HAVE_GETRUSAGE | |
struct rusage ru; | |
pid = wait3((void *)&status, WAITFLAGS, &ru); | |
# else | |
pid = wait3((void *)&status, WAITFLAGS, NULL); | |
# endif | |
#else | |
# ifdef HAVE_WAITPID | |
pid = waitpid(-1, &status, WAITFLAGS); | |
# else | |
pid = wait(&status); | |
# endif | |
#endif | |
if (pid == -1) { | |
if (errno != ECHILD) { | |
perror("wait failed"); | |
return errno; | |
} | |
} | |
return 0; | |
} |
.PHONY: all test clean | |
.IGNORE: test | |
all: wait3_getrusage wait3 waitpid wait | |
wait3_getrusage: main.c | |
gcc main.c -D HAVE_WAIT3 -D HAVE_GETRUSAGE -o wait3_getrusage | |
wait3: main.c | |
gcc main.c -D HAVE_WAIT3 -o wait3 | |
waitpid: main.c | |
gcc main.c -D HAVE_WAITPID -o waitpid | |
wait: main.c | |
gcc main.c -o wait | |
test: wait3_getrusage wait3 waitpid wait | |
./wait3_getrusage | |
./wait3 | |
./waitpid | |
./wait | |
clean: wait3_getrusage wait3 waitpid wait | |
rm -rf wait3_getrusage wait3 waitpid wait |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment