开发者

Parent process does not catch all his child processes

开发者 https://www.devze.com 2023-01-25 11:34 出处:网络
I have following problem: I have main (paren开发者_StackOverflow中文版t) procces, which creates another processes (childs) using fork function. I am catching child\'s status to eliminate zombies. Whe

I have following problem:

I have main (paren开发者_StackOverflow中文版t) 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消