Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <unistd.h>
- #include <stdlib.h>
- #include <sys/wait.h>
- #include <sys/stat.h>
- #include <sys/types.h>
- #include <fcntl.h>
- int main(){
- int status;
- //subshell
- int pid=fork();
- if(pid){
- waitpid(pid,&status,0);
- return status;
- } else{
- int pip[2];
- pipe(pip);
- int st;
- //cat
- int pid1=fork();
- if(!pid1){
- dup2(pip[1],1);
- close(pip[1]);
- close(pip[0]);
- execlp("cat","cat","a",NULL);
- }
- //cut
- int pid2=fork();
- if(!pid2){
- dup2(pip[0],0);
- close(pip[0]);
- close(pip[1]);
- //redirection
- int out=open("out",O_CREAT|O_WRONLY|O_APPEND,644);
- dup2(out,1);
- close(out);
- execlp("cut","cut","-d;","-f1",NULL);
- }
- close(pip[1]);
- close(pip[0]);
- waitpid(pid1,&st,0);
- waitpid(pid2,&st,0);
- //echo
- if(WEXITSTATUS(st)>0){
- if(!fork()){
- execlp("echo","echo","benis",NULL);
- }
- wait(&st);
- }
- exit(st);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement