-1

I am still new to OS domnain. Currently i am trying to implement a shell in C, one of the main feature being the ability to pipe. My question is: After executing the fork dup and other needed processes how should i write inside the execl in case i have multiple arguments. For example once a I would have a pipe 3 processes like sth | sth | sth other times with two like sth | sth

1 Answers1

0

Lets say you have simple pipe like ls | wc. It could possibly be visualized like this:

        +----+                                    +----+
------> | ls | ---------------------------------> | wc | ------->
(stdin) +----+ (pipe write end)   (pipe read end) +----+ (stdout)

Each program needs a separate child process, created with fork from the main shell process. Each child-process then calls exec as you would usually do.

Generally speaking, for a pipe containing n programs, you need n processes and n - 1 pipes. It can be generalized and put into a loop.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621