The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-24-2008
mtobin1987 mtobin1987 is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 2
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
  #2 (permalink)  
Old 04-25-2008
reborg's Avatar
reborg reborg is offline Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,190
Ok, homework/coursework is not allowed here, but you appear to have a genuine effort so I am going to allow this thread to stay open.
  #3 (permalink)  
Old 04-25-2008
mtobin1987 mtobin1987 is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 2
I figured it out, I did just have to close some of the pipe descriptors..thanks anyway though
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 07:26 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0