I am trying to implement a linux shell that supports piping. I have already done simple commands, commands running in background, redirections, but piping is still missing.<
Look into the pipe()
standard library call. This is used to create a pipe. You must of course do part of the work before you fork()
, in order for the child process to inherit the file descriptor properly.
Also note the order of the arguments to dup2()
:
int dup2(int oldfd, int newfd);
dup2() makes newfd be the copy of oldfd, closing newfd first if necessary