On Mon, 17 Jan 2005, crisppy f wrote:
hi once again i am clear abt my ques???? so i repeat...
i have to kill zombie process which is hanging around in process listing. but i am not able to kill it(means kill 9 23234 is not wrking). i need to do it becoz somewhere its not allowing me to start the same type of application again. and main thing i cannot restart the computer which can remove this process as i am working on main server which cant be stopped for sometime for this. and i think as Amish said (kill -l 1) will work logically. i'll tell you all after some time whether this worked or not.
Do `ps -l` to find the parent of the Zombie and kill that process(parent).
Let me explain it more clearly about zombie, then you decide what you want to do with that...
Consider the following code...
<code> Creation of a Zombie process...
int main(void) { int pid; if((pid=fork())<0) puts("fork error"); else if(pid==0) // If the process getting executed is child exit(0); // I am terminating child.
sleep(5); // Parent still exists and sleeping system("ps -l"); // lists the child process as zombie exit(0); // Parent exits }
</code>
In the above code I am creating a zombie as I am terminating child before parent. At the end I am doing an explicit exit() of parent which will remove the zombie from the process table.
Now see the following code...
<code> A Zombie that will never get removed until you kill the parent or a system reboot.
int main(void) { int pid; if((pid=fork())<0) puts("fork error"); else if(pid==0) exit(0);
system("ps -l"); while(1); // The parent will never exit... }
</code>
Now the only way to remove the Zombie from the process table is to kill the parent of that. The above program is an example for badly written application.
Zombie is not a bad thing, its a normal process state. Zombie state is designed because most of the times parent can't wait for the child till child's completion, but parent want to know about child's details. If the child is not in Zombie state there is no way for the parent to know the timing details etc of the child.
In the earlier mail I said almost all the processes in the unix environment goes to Zombie state on exit because a process spawns lot of processes and can't wait for each and everyone. So on exit child goes to zombie state and sends a signal(SIGCHLD, I think) to the parent. If the parent can wait() at that point of time, the child is removed from the process table. If the parent is busy with something else and can't wait() at that point of time, the child will be in the process table entry as a Zombie till parent waits on it. In some implementations when the parent ignores the death of a child signal(SIGCHLD), the kernel directly removes the process entry of the zombie instead of waiting for parent's wait.
So the only way to kill... err... terminate a process in the Zombie state is by killing the parent. Normally you don't have to do that as on the exit of the parent the zombies get cleared but if an application is badly written then you might have to do it.
Thanks & Regards, -- Rajendra Prasad Murakonda, ETU division, C-DAC Mumbai (erstWhile NCST). Off Phone : 91 22 27565303 extn : 302 Mobile(WLL) : 0 93235 83185 rajncst@yahoo.co.in , rajendra.prasad@gmail.com