I am into this weird behaviour where I have my main program and a forked child. They are piped like this(the numbers are file descriptors):
___parent___
| | ____child_____
| 0 stdin | | |
| 1 pipe1[1]----------. | 1 stdout |
| 2 pipe2[1]----------.\ | 2 stderr |
|____________| \`----------> 3 pipe1[0] |
`----------> 5 pipe2[0] |
|______________|
So parent gets input from stdin but redirects stdout and stderr to two pipes. The child has closed its stdin and uses the read ends of the pipes instead.
Then I have a function to just kill the child:
void killChild(){
printf("Killing %d\n", (int)childID);
fflush(stdout);
kill(childID, SIGKILL);
waitpid(childID, NULL, 0); // getting rid of the zombie
}
The child gets succesfully killed but the problem is that the parent itself gets killed as well. I checked the PID of the child and it's correct.
So why does the parent die?