2 way ipc

This is a discussion on 2 way ipc within the C Programming forums, part of the General Programming Boards category; Hi, I need to have one program Called Referee execute 2 other programs A and B that accept input with ...

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    2

    2 way ipc

    Hi, I need to have one program Called Referee execute 2 other programs A and B that accept input with stdin and output to stdout. I need to be able to communicate with them and then close the pipe and the programs and execute a new set of programs in a cycle. Here is what I have right now. I am guessing it is wrong

    Code:
    pipe(p1Input); //input 
    pipe for A  pipe(p1Output); //output pipe for A  
    if((pid = fork()) == - 1){ //fork referee  	
    //Error  	
        perror("There was an error creating a new process");  	
        exit(0);  }
    else if(pid == 0){  	
    //Child  	
        dup2(p1Input[0], fileno(stdin));  //set the input to be stdin
        close(p1Input[1]);//close the other end of the pipe
        dup2(p1Output[1], fileno(stdout));//set the output to be out
        close(p1Output[0]);//close the other end of the pipe
        setvbuf(stdout,(char*)NULL,_IONBF,0);	//not too sure if i ned hat
        execl(argv[pOne], NULL);//execute A
    }else{  	//Parent
        dup2(p1Input[1], fileno(stdout)); //set the output to be stdout
        close(p1Input[0]);	//close the other end of the pipe
        dup2(p1Output[0], fileno(stdin)); //set the input to be stdin
        close(p1Output[1]);	//close the other end of the pipe
        setvbuf(stdout,(char*)NULL,_IONBF,0); //not too sure if i need that
         printf("INPUT\n");
         //Now im not too sure how i would read what A is sending me.
         wait(&status);
    }
    Sorry messed up had to reedit

    Thank for your help
    Last edited by mmnoname; 03-24-2006 at 12:07 PM.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,752
    I'm guessing you need to press the edit button to make your code occupy more than ONE line
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Mar 2006
    Posts
    2
    I fixed the code. Sorry about that. it should be alot more clear now. I hope someone can help me

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simulating wireless netowork using IPC
    By tenkasian in forum C Programming
    Replies: 3
    Last Post: 03-23-2009, 05:16 PM
  2. Segmentation fault - IPC
    By kbfirebreather in forum C Programming
    Replies: 7
    Last Post: 02-01-2009, 03:17 PM
  3. Ipc
    By Rhidian in forum C Programming
    Replies: 2
    Last Post: 03-24-2005, 03:42 AM
  4. a question regarding ipc
    By netwizio in forum Linux Programming
    Replies: 6
    Last Post: 01-10-2004, 01:55 AM
  5. IPC vs RPC
    By hermit in forum Tech Board
    Replies: 7
    Last Post: 09-09-2002, 10:58 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21