GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 18-May-2009, 08:50
aliz2000 aliz2000 is offline
New Member
 
Join Date: May 2009
Posts: 1
aliz2000 is on a distinguished road

Various programs connect via pipes


Hi all,

i am currently stuck on my program

my program basically connects prog1 > prog2 > prog3.
this will be done using pipes.

output of prog1> input prog2 output > input prog3

my program just basically hangs when i try to run it.

if anyone could point me in the right direction would be great, i have been stuck on this for dayyss.

am i going about this the correct way. any help would be great.

here is my code:

CPP / C++ / C Code:

#include <ctype.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/wait.h>
main()
{ 


int p_des[2];
int p_des2[2];
pipe( p_des ); /* The pipe descriptor */
pipe( p_des2 );


           if ( fork () == 0 )
           {


              dup2(p_des[1], 1);
              close(p_des[0]); /* process-A closing read end of the pipe */

              execlp("./task1", "task1", 0);
                 /*** exit(1); ***/
          }

else
if ( fork () == 0 )
           { 

           dup2(p_des2[1],1);
           close(p_des2[0]);  



           dup2(p_des[0], 0);
           close(p_des[1]);  
           execlp("./task2", "task2", 0);

        }


else
if ( fork () == 0 )
        { 


         dup2(p_des[0], 0);
         close(p_des[1]); /* process-B closing write end of the pipe */

         execlp("./task3", "task3", 0);
         /*** exit(1); ****/
       }

else
{ 
     close(p_des[1]); /* parent closing both the ends of pipe */
     close(p_des[0]);
     close(p_des2[1]); /* parent closing both the ends of pipe */
     close(p_des2[0]);

    wait(0);
    wait(0);
    wait(0);
 }
fflush(stdout);
}

 
 

Recent GIDBlogVista ?Widgets? on Windows XP by LocalTech

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 20:26.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.