![]() |
|
|
|
|
|||||||
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| question about grep, cut, and piping | dyrt | Shell Programming and Scripting | 1 | 02-28-2008 07:12 PM |
| Piping to ex from a script | mph | Shell Programming and Scripting | 2 | 10-11-2007 12:54 PM |
| Piping in UNIX | simo007 | UNIX for Dummies Questions & Answers | 3 | 05-22-2007 11:40 PM |
| piping | lnatz | Shell Programming and Scripting | 1 | 07-13-2006 11:30 PM |
| Help (Piping ls, tr, cut) | scan | Shell Programming and Scripting | 2 | 02-11-2006 04:40 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
Piping Question
I have a piping question, I am trying to implement piping on my own shell and am having some trouble...esentially I am trying to make something to do command|command|command.
I can get it to work fine if the last pipe command is not forked, but executes in the shell and then exits..but I need it to fork. I tryed the following, but it will hang..any suggestions? I have a feeling it has something to do with closing/opening descriptors but i don't know...thanks.: Code:
int pipe1[2], pipe2[2];
pipe(pipe1);//create first pipe
pid_t PID=fork();
if(PID==0){
close(1);
dup(pipe1[1]);
close(pipe1[0]);
close(pipe1[1]);
execvp(*argv,argv);
printf("operation failed");
} else {
pipe(pipe2);
pid_t PID2=fork();
if (PID2==0) {
close(0);
dup(pipe1[0]);
close(1);
dup(pipe2[1]);
close(pipe1[0]);
close(pipe1[1]);
close(pipe2[0]);
close(pipe2[1]);
execvp(*argv2, argv2);
} else {
pid_t PID3=fork();
waitpid(PID3,&status,0);<-----Not sure about this
if(PID3==0){
close(0);
dup(pipe2[0]);
close(pipe1[0]);
close(pipe1[1]);
close(pipe2[0]);
close(pipe2[1]);
execvp(*argv3, argv3);
}
}
}
Last edited by Yogesh Sawant; 04-25-2008 at 12:33 AM. Reason: added code tags |
| Forum Sponsor | ||
|
|
| Thread Tools | |
| Display Modes | |
|
|