Recursive piping in Unix again

后端 未结 1 362
無奈伤痛
無奈伤痛 2020-12-31 22:14

I know this topic came up already several times, but I\'m still stuck at one point. I need to write a program that emulates cmd1 | cmd2 | cmd3 ... piping.

相关标签:
1条回答
  • 2020-12-31 22:37

    Not an expert, but it seems the following line is the problem:

    ((close(fd[1]) == -1) || (close(in_fd) == - 1))
    

    Try not to close in_fd there.

    I think, the parent is trying to close the same fd that is closed by child.
    When you use dup2() you do not need to close the files as dup2() already closes the file.

    0 讨论(0)
提交回复
热议问题