Skip to content

Instantly share code, notes, and snippets.

@knqyf263
Last active January 30, 2019 08:09
Show Gist options
  • Save knqyf263/ac2367c07ace91d6cb9155915fd8ed96 to your computer and use it in GitHub Desktop.
Save knqyf263/ac2367c07ace91d6cb9155915fd8ed96 to your computer and use it in GitHub Desktop.
Infinite loop
#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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment