Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sys/wait.h>
- #include <stdio.h>
- #include <sys/types.h>
- #include <unistd.h>
- #include <stdlib.h>
- #include <string.h>
- int main(int argc, char *argv[]) {
- char word[4097];
- int counter = 0;
- pid_t pid;
- pid_t root = -1;
- do {
- if (scanf("%s", word) != EOF) {
- counter++;
- pid = fork();
- if (counter == 1 && pid > 0) root = pid;
- } else {
- if (counter == 0) {
- printf("%d", counter);
- return 0;
- }
- return counter;
- break;
- }
- } while (counter <= 255 && pid == 0);
- if (pid > 0) {
- int status;
- waitpid(pid, &status, 0);
- int exit_status = WEXITSTATUS(status);
- if (pid == root) {
- printf("%d", exit_status);
- return 0;
- }
- return exit_status;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement