0 оценок0% нашли этот документ полезным (0 голосов)
6 просмотров3 страницы
When a child process terminates, but the parent process isn't interested in the outcome because it didn't waited for the childs response. The remaining process table entry will be delete, when the parent process reaps the child by gathering the exit code. With Solaris you can reap such processes manually. The preap forces the parent to call wait() system call on the child.
When a child process terminates, but the parent process isn't interested in the outcome because it didn't waited for the childs response. The remaining process table entry will be delete, when the parent process reaps the child by gathering the exit code. With Solaris you can reap such processes manually. The preap forces the parent to call wait() system call on the child.
When a child process terminates, but the parent process isn't interested in the outcome because it didn't waited for the childs response. The remaining process table entry will be delete, when the parent process reaps the child by gathering the exit code. With Solaris you can reap such processes manually. The preap forces the parent to call wait() system call on the child.
Once in a while you will see some strange processes with <defunct>
instead of a process name. This happens when a child process terminates,
but the parent process isnt interested in the outcome because it didnt waited for the childs response. Almost all resources of the child process are freed up at the moment with the exception of the entry in the process table. The parent process need it to get the exit code from its child, thus you cant simply delete it on the termination of the child. The remaining process table entry will be delete, when the parent proccess reaps the child process by gathering the exit code. But when the parent forgets to reap the child, its undead, its defunct. Or to stay in the terminology: Youve produced a Zombie process.
Lets create such a process. Its really easy, we just have to create a long running process forking away a child but we dont use the wait() system call to gather its response at the exit. bash-3.2$ nohup perl -e "if (fork()>0) {while (1) {sleep 100*100;};};"& Okay, lets check for our processes. In the output of ps -ecl the zombie processes are marked with a Z: bash-3.2$ ps -ecl |grep "Z" F S UID PID PPID CLS PRI ADDR SZ WCHAN TTY TIME CMD 0 Z 100 27841 27840 - 0 - 0 - ? 0:00 <defunct> bash-3.2$ A kill -9 to this process is without effect. Obviously, a zombie will go away when you terminate the parent process, but that isnt alway an option. How can you get rid of this Zombies? Okay, with Solaris you can reap such processes manually. The preap forces the parent to reap the child by calling wait() system call on the child. bash-3.2$ preap 27841 27841: exited with status 0 And when you look in the process table again you will see, that the zombie founds its peace... bash-3.2$ ps -ecl |grep "Z" F S UID PID PPID CLS PRI ADDR SZ WCHAN TTY TIME CMD Obviously, you should ask yourself, why an application leaves such zombie processes, when the task of reaping them away manually gets a frequent task. Often its because of bad programming style.
============================================== ============================================== How to kill a defunct process (most of the time) Defunct processes are processes that have become corrupted in such a way the no long can communicate (not really the right word, more like signal each other) with their parent or child process. So kill the parent or child and 99% of the time (around here at least) the defunct process will go away! No parent or child, you're out of luck, or look for a stuck automount. # # list detached non root processes on Solaris # clarion:/# ps -ef | grep -v \ \ root | grep -v pts/ | less UID PID PPID C STIME TTY TIME CMD xxxxxx 168 1 0 Jan 13 ? 0:00 /usr/lib/nfs/statd yyyy 28835 28789 0 Apr 07 ? 2:05 xbiff++ zzz 13868 1 0 0:00 <defunct> aaaa 24724 24721 0 Apr 02 ? 0:02 /usr/openwin/bin/xload -hl red -g eom +396+26 nnnn 28789 28786 0 Apr 07 ? 0:00 /pkg/local/bin/tcsh -c xbiff++
# now use /usr/proc/bin/ptree to find parent or child ## Linux users might try ps -ef --forest | less
# ta daa ! # # or # bash# /usr/proc/bin/ptree `ps -ef | grep -v ^\ \ \ \ root | awk '/<defunct>/ {print $2}'` | less Written with vi, and should be viewable by any browser!
Killing zombie process by NIX Craft on May 26, 2006 36 comments LAST UPDATED September 19, 2006 in FreeBSD, Linux, Troubleshooting Zombie process is an inactive computer process, according to wikipedia article, "...On Unix operating systems, a zombie process or defunct process is a process that has completed execution but still has an entry in the process table, allowing the process that started it to read its exit status. In the term's colorful metaphor, the child process has died but has not yet been reaped..." So how do I find out zombie process? Use top or ps command: # top OR # ps aux | awk '{ print $8 " " $2 }' | grep -w Z Output: Z 4104 Z 5320 Z 2945 How do I kill zombie process? You cannot kill zombies, as they are already dead. But if you have too many zombies then kill parent process or restart service. You can kill zombie process using PID obtained from any one of the above command. For example kill zombie proces having PID 4104: # kill -9 4104 Please note that kill -9 does not guarantee to kill a zombie process (see below for more info). How do I automate zombie process killing? Write a script and schedule as a cron job.