0

What I mean is, can I use fork() and exec() to implement calls like: ls -l | wc | wc , where I have used 2 pipes.

dbush
  • 205,898
  • 23
  • 218
  • 273
  • YEs, you can. The shell is written in C, and it does it. – Barmar Sep 17 '15 at 21:17
  • Call `pipe` twice to set up the two pipes, call `fork` three times, connect all the pipes to the appropriate `stdin` and `stdout` with `dup2`, and then `exec` the programs. – Barmar Sep 17 '15 at 21:19

1 Answers1

0

You'll have to chain your forks and execs see here for an example of pipe chaining.

You'll have to use dup(2) to duplicate the stdout of one process to the stdin of the next process in the chain.

Community
  • 1
  • 1
asdf
  • 2,927
  • 2
  • 21
  • 42