Skip to content

Instantly share code, notes, and snippets.

@jeremyd2019
Last active May 21, 2024 00:27
Show Gist options
  • Save jeremyd2019/3156721497096d0bba00ef19a507f619 to your computer and use it in GitHub Desktop.
Save jeremyd2019/3156721497096d0bba00ef19a507f619 to your computer and use it in GitHub Desktop.
reproducer for cygwin hangs under emulation on arm64
#include <stdio.h>
#include <sys/wait.h>
#include <unistd.h>
#ifndef BINARY
#define BINARY "/bin/true"
#endif
#ifndef ARG
#define ARG "0.1"
#endif
int main(int argc, char ** argv)
{
while (1)
{
int pid;
printf("Starting group of 100x " BINARY " " ARG "\n");
for (int i = 0; i < 100; ++i)
{
pid = fork();
if (pid == -1)
{
perror("fork error");
return 1;
}
else if (pid == 0)
{
if ((pid = fork()) == 0)
{
char * const args[] = {BINARY, ARG, NULL};
execv(BINARY, args);
perror("execv failed");
_exit(5);
}
if (pid == -1)
{
perror("inner fork error");
_exit(1);
}
else
{
_exit(0);
}
}
else
{
int status;
if (waitpid(pid, &status, 0) == -1)
{
perror("waitpid error");
return 2;
}
else if (status != 0)
{
fprintf(stderr, "subprocess exited non-zero: %d\n", status);
return WEXITSTATUS(status);
}
}
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment