{"id":1086,"date":"2018-10-21T04:17:30","date_gmt":"2018-10-21T04:17:30","guid":{"rendered":"https:\/\/www.appservgrid.com\/paw92\/?p=1086"},"modified":"2018-10-23T00:50:02","modified_gmt":"2018-10-23T00:50:02","slug":"how-to-kill-defunct-or-zombie-process-in-linux","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/10\/21\/how-to-kill-defunct-or-zombie-process-in-linux\/","title":{"rendered":"How to kill defunct or zombie process in linux?"},"content":{"rendered":"<p><b> <\/b><b>HOW TO KILL DEFUNCT OR ZOMBIE PROCESS<\/b><\/p>\n<p>A <b>&#8220;defunct&#8221;<\/b> processes<br \/>\nis also known as a <b>&#8220;zombie&#8221; <\/b>processes. A Zombie<br \/>\nprocess is referred as <b>dead process <\/b>which is receding on your<br \/>\nsystem though it\u2019s completed executing. In one shot we can say it\u2019s a dead<br \/>\nprocesses which is still in RAM. This process will be in your process table and<br \/>\nconsuming your memory. Having more defunct process will consume your memory<br \/>\nwhich intern slows your system. We have to kill the defunct process in order to<br \/>\nfree RAM and make system stable.<\/p>\n<p><b>What is a zombie process?<\/b><\/p>\n<p>When a process finishes execution, it will<br \/>\nhave an exit status to report to its parent process. Because of this last<br \/>\nlittle bit of information, the process will remain in the operating system\u2019s<br \/>\nprocess table as a zombie process, indicating that it is not to be scheduled<br \/>\nfor further execution, but that it cannot be completely removed (and its<br \/>\nprocess ID cannot be reused) until it has been determined that the exit status<br \/>\nis no longer needed.<\/p>\n<p>When a child exits, the parent process will<br \/>\nreceive a SIGCHLD signal to indicate that one of its children has finished<br \/>\nexecuting; the parent process will typically call the wait() system call at<br \/>\nthis point. That call will provide the parent with the child\u2019s exit status, and<br \/>\nwill cause the child to be reaped, or removed from the process table.<\/p>\n<p><b>Why<br \/>\ndefunct process are created?<\/b><\/p>\n<p><b>Ans<br \/>\n:<\/b> When ever a process ends<br \/>\nall the memory used by that process are <b>cleared and assigned<\/b> <b>to<br \/>\nnew process <\/b>but due to programming <b>errors\/bugs<\/b> some<br \/>\nprocesses are still left in process table. These are created when there is no<br \/>\nproper communication between parent process and child proces<\/p>\n<p><b>How do I remove zombie<br \/>\nprocesses from a system?<\/b><\/p>\n<p>Well, first you can wait.<br \/>\nIt\u2019s possible that the parent process is intentionally leaving the process in a<br \/>\nzombie state to ensure that future children that it may create will not receive<br \/>\nthe same pid. Or perhaps the parent is occupied, and will reap the child<br \/>\nprocess momentarily.<\/p>\n<p>Secondly, you can send a<br \/>\nSIGCHLD signal to the parent (\u201ckill -s SIGCHLD &lt;ppid&gt;\u201c). This will cause<br \/>\nwell-behaving parents to reap their zombie children.<\/p>\n<p>Finally, you can kill the<br \/>\nparent process of the zombie. At that point, all of the parent\u2019s children will<br \/>\nbe adopted by the init process (pid 1), which periodically runs wait() to reap<br \/>\nany zombie children. Then system need reboot to kill zombie process.<\/p>\n<p><b>Interview<br \/>\nquestions &amp; answers<\/b><\/p>\n<p><b>1. How to find a defunct<br \/>\nprocess?<\/b><\/p>\n<p>Run \u201cps aux\u201d and look for a<br \/>\nZ in the STAT column.<\/p>\n<p>ps aux | awk<br \/>\n&#8216;&#8221;[Zz]&#8221; ~ $8 { printf(&#8220;%s, PID = %dn&#8221;, $8, $2); }&#8217;<\/p>\n<p><b>2. How can I kill a<br \/>\ndefunct process?<\/b><\/p>\n<p><b>Ans :<\/b> Just use kill command<\/p>\n<p><b>3. Still not able to<br \/>\nkill?<\/b><\/p>\n<p><b>Ans :<\/b> Then use kill -9 to force<br \/>\nkill that process<\/p>\n<p><b>4. Still have an issue in<br \/>\nkilling it?<\/b><\/p>\n<p><b>Ans :<\/b> Then try to kill it\u2019s<br \/>\nparent id and then defunct.<\/p>\n<p>#kill<br \/>\nparent-id-of-defunct-pid<\/p>\n<p>#kill -9<br \/>\nparent-id-of-defunct-pid<\/p>\n<p><b>Ans<\/b> : If you still find defunct<br \/>\nprocess eating up RAM then last and final solution is to reboot your<br \/>\nmachine(This is not preferred on production boxes).<\/p>\n<p><b>6.What is orphan process?<\/b><\/p>\n<p><b>Ans :<\/b> An orphan process is said<br \/>\nto be a process which runs through parent process is terminated, these process<br \/>\ndo not know what to do and when to terminate.<\/p>\n<p><b>7. What is difference<br \/>\nbetween orphan and defunct processes?<\/b><\/p>\n<p><b>Ans :<\/b> A defunct process is a dead<br \/>\nprocess where there is no execution happening whereas orphan process is a live<br \/>\nprocess which is still in execution state but don&#8217;t have parent process<\/p>\n<p><a href=\"https:\/\/www.linuxforfreshers.com\/2017\/11\/how-to-kill-defunct-or-zombie-process_7.html\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>HOW TO KILL DEFUNCT OR ZOMBIE PROCESS A &#8220;defunct&#8221; processes is also known as a &#8220;zombie&#8221; processes. A Zombie process is referred as dead process which is receding on your system though it\u2019s completed executing. In one shot we can say it\u2019s a dead processes which is still in RAM. This process will be in &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/10\/21\/how-to-kill-defunct-or-zombie-process-in-linux\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to kill defunct or zombie process in linux?&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1086","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/1086","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=1086"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/1086\/revisions"}],"predecessor-version":[{"id":1354,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/1086\/revisions\/1354"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=1086"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=1086"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=1086"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}