Operating System - HP-UX
1748201 Members
3012 Online
108759 Solutions
New Discussion

Killing processes that become to Zombie

 
Yaroki
Super Advisor

Killing processes that become to Zombie

Dears,

 

As a part of the system, there is a procedure that killing process in my HP-UX (B.11.11), by kill -9 PID.

Lately, I've noticed that these processes become to Zombies when kill -9 is activated on them. Therefore I enforce to restart the inner application. This action also kills processes, but it also terminates the whole application.

How can I overcome the problem without restart the application?

BR,

 

Yali

 

4 REPLIES 4
Matti_Kurkela
Honored Contributor

Re: Killing processes that become to Zombie

Short answer: send in a bug report to the developers of the "inner application" and have them fix the application.

 

Longer answer:

When a process dies and its parent process (PPID in the "ps -ef" listing) does not immediately read the result code of the dead process, the dead process becomes a zombie. The zombie process cannot be killed because it is already dead: all the memory it occupied is already freed, except a slot in the system's process table. Once the parent process reads the result code (typically, by using a system call of the wait() family), the system will automatically clean up the zombie process from the process table. But if the zombies are not cleaned, the zombies may accumulate and fill the process table so that no new processes can be created. If this happens, you may have to crash and reboot the system.

 

If the parent process dies before reading the result code, the zombie process is automatically adopted by process #1, the "init" process. Init is the "mother of all processes": when the system starts up, it starts all the other userspace processes. When the system is running normally, init spends all its time monitoring its child processes (both real and adopted ones) and will immediately read the result code of any adopted zombie process, allowing the zombie to be cleaned up even if its real parent did not do it.  This is why a common (half-joke) advice to a zombie problem is "Kill the evil zombie master!", where the "zombie master" means the parent process of the zombies. Killing it will cause the zombies to be adopted by init, which will clean them up.

 

If zombie processes are accumulating in the process table, that means the parent process of the zombies (the "inner application" in your case, I guess?) is not doing its job of managing its child processes, and it should be fixed.

 

If the "inner application" needs to do some work while its child processes are running, it cannot spend all its time wait()ing for its children. The standard solution for this is to have the "inner application" set up a signal handler function for SIGCHLD: this is a signal sent by the system to the parent process whenever one of its children dies. The signal handler function can then call wait(). As the SIGCHLD indicates there is at least one dead child process, the wait() system call will return immediately, and the dead child process will be laid to rest and won't remain as a zombie.

 

Setting up the SIGCHLD signal handler is something that the application developer should do: if you do not have the source code of the application, adding a signal handler to the application would be very difficult or impossible.

MK
Dennis Handly
Acclaimed Contributor

Re: Killing processes that become to Zombie

>there is a procedure that killing process in my HP-UX (B.11.11), by kill -9 PID.

 

You should always do a normal kill before going on to kill -9.

 

Topics about zombies, zombie masters and zombie slayers:

http://h30499.www3.hp.com/t5/tag/zombie%20master/tg-p

http://h30499.www3.hp.com/t5/tag/zombie/tg-p

http://h30499.www3.hp.com/t5/tag/zombie%20slayer/tg-p

Yaroki
Super Advisor

Re: Killing processes that become to Zombie

dear Matti,

 

Thank you for the explanation.

 

Regarding the short answer, you right, I suspect it will be this kind of problem. Unfortunately, I am not holding the code...

Regarding the longer one, everything is clear, except one thing. Why do processes from both tape PPID and PID (even thought they became zombies) can be terminated when I restart the inner application? I guess this action kill the main process, but isn't it like killing manully PID like kill -9 (which is not the solution)?

 

Yali

 

 

Matti_Kurkela
Honored Contributor

Re: Killing processes that become to Zombie

When you stop the inner application that is the parent of the zombie processes, the zombies will become orphaned: their original parent process does not exist any more. In Unix systems this is not a valid situation: each process must have a PPID that refers to some existing process. So the operating system must do something to fix it. In this situation, the operating system will automatically change the PPID of the orphaned children to 1, so they will become "adopted" children of process #1 (init).

 

The "init" process is designed to accept adopted processes. If it receives a zombie as a result of the adoption, it will immediately call wait() to clear the zombie. Init can adopt living processes too: it does nothing special to them as long as they stay alive. When they die, init will call wait() on them so they won't remain as zombies.

 

Only a parent process can lay to rest its zombie children. As long as the original parent process (the inner application) exists and does not take care of its children, init cannot help; but as soon as the inner application dies, the OS kernel will assign the children to an adoptive parent (init), which is more responsible and will immediately lay the zombies to rest.

MK