Thread: pipe!

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    81
    Rep Power
    12

    pipe!


    Hi I have two programs, I want the output of one to be the input of the other, only it is not happening. Right now I forktwice to protect the main program if the other two exec programs crash nothing bad happens. Can anyone help? Thanks!
  2. #2
  3. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,158
    Rep Power
    2222
    I'm looking at page 526 of O'Reilly's "Understanding the Linux Kernel", "Using a Pipe".

    In their description, the parent uses the pipe() system call, then forks twice and closes the pipe's file descriptors (3 for the read channel, 4 for the write channel).

    The first child (read "left side of the pipe") does a dup2(4,1) to make the pipe's write channel its stdout (I guess it should have closed stdout first). Then it closes descriptors 3 & 4 and calls execve().

    The second child (read "right side of the pipe") similarly does a dup2(3,0) to make the read channel its stdin. Then it closes descriptors 3 & 4 and calls execve().
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    81
    Rep Power
    12

    hmm


    I am doing that only using execvp but it just kind of sits there
    no idea what is going on....
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Posts
    3
    Rep Power
    0
    I'm not sure that you're fork statements are happening correctly. Make sure to check the return values on the fork statement. Also be sure to terminate your children, you'll run out of avaiable processes.

    Hope that helps...:)
  8. #5
  9. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,158
    Rep Power
    2222
    And if you want to use trace statements for the child processes to report their status, you should still have stderr to work with.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    81
    Rep Power
    12

    Thanks!


    I got it to work! :)

IMN logo majestic logo threadwatch logo seochat tools logo