Question

I have following problem:

I have main (parent) procces, which creates another processes (childs) using fork function. I am catching child's status to eliminate zombies. When there is 1 child process, it is catched correctly, but when there are more processes (aprx. 30) created by parent process, there are aprx. 4 zombies left = parent does not catch all the children (return status/state = <defunct>).

Child status is catched using

void selfkill(int status) {
    wait(&status);
}

signal(SIGCHLD, selfkill);

Thanks in advance.

Was it helpful?

Solution

You should probably use waitpid() with WNOHANG in a loop inside the signal handler.

What probably happens is that not all the signals are delivered - because some of them arrive too close to each other. You could perhaps alleviate that problem by using sigaction() instead of signal(), too.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top