0

I am writing a simple shell and I would like to implement a pipes.

So, let's consider:

<command1> | <command2> | <command3> | ...

Now, my idea is:

Start command1 and waitpid for him. Then run command2 and waitpid for him. And so on.

  1. Is it a good idea?

  2. How to implement?:

    <command1> | <command2> | <command3> &
    
David Ranieri
  • 39,972
  • 7
  • 52
  • 94
J. Doe
  • 101
  • 8
  • I think it is not a good idea. If you do so, you will have to save all of command1's output (potensially very big) to somewhere (memory or disk) and then pass it to command2. – MikeCAT Sep 21 '15 at 15:15
  • 1
    This question is similar to the following: http://stackoverflow.com/questions/12981199/multiple-pipe-implementation-using-system-call-fork-execvp-wait-pipe-i – rkachach Sep 21 '15 at 15:23

1 Answers1

0

Now, my idea is:

Start command1 and waitpid for him. Then run command2 and waitpid for him. And so on.

Is it a good idea?

No. Start maybe reading pipe(2). Processes have to run at the same time for communicating through a pipe. (and you want to use actual pipes for this, not some temporary storage).

Community
  • 1
  • 1