Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <sys/wait.h>
- int
- main(void)
- {
- int a;
- pid_t pid = 0;
- pid = fork();
- if (pid == -1) {
- printf("-1\n");
- return 0;
- }
- if (!pid) {
- while (scanf("%d", &a) == 1) {
- pid = fork();
- if (pid == -1) {
- printf("-1\n");
- return 1;
- } else if (pid) {
- while (wait(NULL) == -1);
- printf("%d\n", a);
- _exit(0);
- }
- }
- _exit(0);
- }
- while (wait(NULL) == -1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement