Pipe implementation

前端 未结 2 1439
花落未央
花落未央 2020-12-09 21:35

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.<

2条回答
  •  南方客
    南方客 (楼主)
    2020-12-09 21:46

    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

提交回复
热议问题