![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| question about grep, cut, and piping | dyrt | Shell Programming and Scripting | 1 | 02-28-2008 11:12 PM |
| Piping to ex from a script | mph | Shell Programming and Scripting | 2 | 10-11-2007 03:54 PM |
| Piping in UNIX | simo007 | UNIX for Dummies Questions & Answers | 3 | 05-23-2007 02:40 AM |
| piping | lnatz | Shell Programming and Scripting | 1 | 07-14-2006 02:30 AM |
| Help (Piping ls, tr, cut) | scan | Shell Programming and Scripting | 2 | 02-11-2006 08:40 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | 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 03:33 AM.. Reason: added code tags |
|
||||
|
I figured it out, I did just have to close some of the pipe descriptors..thanks anyway though
![]() |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|