- OS: Ubuntu 16.04.3 LTS
- libc: 2.23-0ubuntu10
https://sourceware.org/bugzilla/show_bug.cgi?id=23151
$ gcc main.c
$ ./a.out
aaaaaaaaa
aaaaaaaaa
aaaaaaaaa
aaaaaaaaa
aaaaaaaaa
aaaaaaaaa
aaaaaaaaa
aaaaaaaaa
...
https://sourceware.org/bugzilla/show_bug.cgi?id=23151
$ gcc main.c
$ ./a.out
aaaaaaaaa
aaaaaaaaa
aaaaaaaaa
aaaaaaaaa
aaaaaaaaa
aaaaaaaaa
aaaaaaaaa
aaaaaaaaa
...
#include <stdio.h> | |
#include <stdlib.h> | |
#include <sys/wait.h> | |
#include <unistd.h> | |
int main(){ | |
FILE* fp = fopen("test.txt", "r"); | |
char s[10]; | |
while (fgets(s, 10, fp) != NULL) { | |
pid_t pid = fork(); | |
int status; | |
if (pid == 0) { | |
exit(0); | |
} else { | |
waitpid(pid, &status, 0); | |
} | |
printf("%s\n", s); | |
} | |
} |
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |