Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

kill - does it kill the process right away?

what does kill exactly do?

I have a parent process which is creating 100 (as an example) child processes one after another. At the end of any child's job, I kill the child with kill(pid_of_child, SIGKILL) and I cannot see that in ps output. But if something goes wrong with the parent process and I exit from the parent process with exit(1) (at this point only 1 child is there - I can check tht in ps), at that point I see a lot of <defunct> processes whose ppid is pid of parent process.

How is that possible? did kill not kill the child processes entirely?

like image 308
hari Avatar asked Dec 04 '22 19:12

hari


1 Answers

kill doesn't kill anything. It sends signals to the target process. SIGKILL is just a signal. Now, the standard action for SIGKILL -- the only action, actually, since SIGKILL can't be handled or ignored by a process -- is to exit, that's true.

The "<defunct>" process is a child that hasn't been reaped, meaning that the parent hasn't called wait() to retrieve the exit status of the child. Until the parent calls wait(), the defunct (or "zombie") process will hang around.

like image 60
Ernest Friedman-Hill Avatar answered Dec 07 '22 22:12

Ernest Friedman-Hill