user1710707
user1710707

Reputation: 21

Pipe not executing + signal handling

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

Answers (1)

pilcrow
pilcrow

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:

  1. both children should close their pipe fds after dup2'ing
  2. the code after 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

Related Questions