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
Asked
Active
Viewed 114 times
1 Answers
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
-
i understand the concept my question was about the execl command. if i have 3 arguments do i have to call all of them in the execl – Sir Scroll Nov 07 '20 at 20:04
-
@SirScroll You call the `exec` functions just like you would normally do for any other program your shell tries to run. – Some programmer dude Nov 07 '20 at 20:14