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