Reputation: 21
I am trying to implement a simple two stage pipe in a shell.
When I don't do the second fork and just do the rest of the implementation of the pipe in the parent, it works fine but I exit the shell. That's why I want to do the second fork so I don't exit the shell. But for some reason nothing happens with the above code. Can you help me figure out what may be going wrong? I have a feeling it doesn't wait for both my processes to finish before exiting but I could be wrong.
Upvotes: 1
Views: 102
Reputation: 58589
Solution: close fd[0]
and fd[1]
in the parent.
In the twin fork model, which you want, your parent process (the shell) is keeping its copy of fd[1]
open. With this open, the child pid2
will never see EOF on its standard input fd.
Comments:
execvp
, both above and in your pastie suggests that you think that execvp
will return control under ordinary circumstances. It does not. For this code, at most you probably want to follow the execvp
with a perror
and exit
.Upvotes: 1