Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <unistd.h>
- #include <stdio.h>
- #include <stdlib.h>
- void pipeusage(int writingEnd,int readingEnd,char* message)
- {
- pipefirst(writingEnd);
- }
- void pipefirst(int writingEnd,char* message)
- {
- }
- int main(int argc, char** argv)
- {
- if (argc==1)
- {
- if (!fcntl(68,F_GETFD)) return -1; //wypis peeror
- else lastchild();
- }
- int fd[2];
- if (pipe(fd)==-1) return -1;
- int id = fork();
- char** new_point = (char**)malloc(sizeof(char*)*(argc));
- for(int i=1; i<argc;++i) new_point[i-1]=argv[i];
- new_point[argc] = NULL;
- if (!id)
- {
- close(fd[1]);
- dup2(fd[0],68);
- close(fd[0]);
- execvp("./test_prog",new_point);
- }
- close(fd[0]);
- if (!fcntl(68,F_GETFD))
- {
- pipefirst(fd[1],argv[1]);
- }
- else
- {
- pipeusage(fd[1],68,argv[1]);
- }
- waitid(id);
- free(new_point);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement