Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <unistd.h>
- #include <sys/wait.h>
- int
- main(void)
- {
- setbuf(stdout, NULL);
- FILE *fp = fopen("eee", "r");
- int num, i=0;
- pid_t pid;
- while(fscanf(fp, "%d", &num) != EOF) {
- i++;
- fflush(fp);
- pid = fork();
- if (pid < 0) {
- printf("%d\n", -1);
- fflush(stdout);
- _exit(0);
- } else if (pid > 0) {
- waitpid(pid, NULL, 0);
- printf("%d\n", num);
- fflush(stdout);
- _exit(0);
- }
- //printf("sss");
- }
- printf("%d\n", i);
- //printf("Hello, Dcoder!");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement