I have a small shell that creates children (with fork()) and make them execute some commands with execvp. It support also the & option so the father can run other commands in the meanwhile. When a child die i want to write that on the console and also the child pid, so i defined a sighandler for SIGCHLD:
void backdeadchild(int sig)
{
int pid, exitstat;
pid = wait(&exitstat);
printf("Child with pid: %d died", pid);
}
The problem is that after the handler prints the message also the father closes. I've managed to understand that SIGCHLD returns an EOF in stdin (and whenever father receives EOF it closes), but why SIGCHLD returns EOF? If it's normal.. how to avoid that the father closes?