Reputation: 1082
I have a child process specified by pid
. This process could be:
I would like to kill this process and ensure no zombie remains. Currently my code is
kill(pid, SIGKILL);
int temp;
waitpid(pid, &temp, 0);
Would this work?
EDIT: The process specified by pid
is a child of my program.
Upvotes: 2
Views: 2892
Reputation: 72657
This looks fine so far, but I wonder why you would let case 3 happen. You should perform some bookkeeping, which of your child processes have terminated and are waiting to be reaped.
One way would be to install a handler for SIGCHLD
, setting a flag that a waitpid
is in order. That way you guarantee that all pids are actually those of your child processes.
Upvotes: 2
Reputation: 276
Should work fine, but be sure to check the returnvalue of waitpid. The call may have returned due to a signal.
Upvotes: 2