Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sys/types.h>
- #include <sys/wait.h>
- #include <unistd.h>
- #include <stdio.h>
- #include <stdlib.h>
- //piping entails calling pipe on an array of size two
- //second command details - character pointer to place that points at gnetcat
- int
- main(int ac, char* av[]) {
- char* first_prog = *(av + 1);
- char* second_prog = *(av + 2);
- int first_to_second[2];
- if (pipe(first_to_second) == -1) {
- perror("pipe"), exit(-1);
- }
- int second_to_first[2];
- if (pipe(second_to_first) == -1) {
- perror("pipe"), exit(-1);
- }
- pid_t first_cmd = fork();
- if (first_cmd < 0) {
- //perror here
- }
- if (first_cmd != 0) {
- pid_t second_cmd = fork();
- if (second_cmd < 0) {
- //perror
- }
- if (second_cmd != 0) {
- //this is a parent, we gotta wait here twice
- wait(NULL); //change this to wait4
- wait(NULL);
- } else {
- //this is the 'gnetcat' child
- }
- } else {
- //this is the 'wc' child
- //exec
- write(2, "Starting: %s", first_prog);
- dup2(first_to_second[1], 1);
- //THE REST OF THE WC SECTION
- }
- //first - no args
- //second - many args
- //
- //fork()
- //fork()
- // if (parent) { wait(), wait() }
- //initially double fork
- //check if parent, then double wait
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement