Linux 僵屍進程查殺

来源:http://www.cnblogs.com/kerrycode/archive/2016/04/01/5343482.html
-Advertisement-
Play Games

僵屍進程概念 僵屍進程(Zombie process)通俗來說指那些雖然已經終止的進程,但仍然保留一些信息,等待其父進程為其收屍. 書面形式一點:一個進程結束了,但是他的父進程沒有等待(調用wait / waitpid)他,那麼他將變成一個僵屍進程。通過ps命令查看其帶有defunct的標誌。僵屍進... ...


僵屍進程概念

 

   僵屍進程(Zombie process)通俗來說指那些雖然已經終止的進程,但仍然保留一些信息,等待其父進程為其收屍. 書面形式一點:一個進程結束了,但是他的父進程沒有等待(調用wait / waitpid)他,那麼他將變成一個僵屍進程。通過ps命令查看其帶有defunct的標誌。僵屍進程是一個早已死亡的進程,但在進程表(processs table)中仍占了一個位置(slot)。

  但是如果該進程的父進程已經先結束了,那麼該進程就不會變成僵屍進程。因為每個進程結束的時候,系統都會掃描當前系統中所運行的所有進程,看看有沒有哪個進程是剛剛結束的這個進程的子進程,如果是的話,就由Init進程來接管他,成為他的父進程,從而保證每個進程都會有一個父進程。而Init進程會自動wait其子進程,因此被Init接管的所有進程都不會變成僵屍進程

    與ZOMBIE對應的進程狀態還有RUNNING(正在運行或等待運行狀態),UNINTERRUPTABLE(不可中斷阻塞狀態),INTERRUPTABLE(可中斷阻塞狀態),STOPPED(掛起狀態)等。

關於僵屍進程的維基百科介紹:

On Unix and Unix-like computer operating systems, a zombie process or defunct process is a process that has completed execution (via the exit system call) but still has an entry in the process table: it is a process in the "Terminated state". This occurs for child processes, where the entry is still needed to allow the parent process to read its child's exit status: once the exit status is read via the wait system call, the zombie's entry is removed from the process table and it is said to be "reaped". A child process always first becomes a zombie before being removed from the resource table. In most cases, under normal system operation zombies are immediately waited on by their parent and then reaped by the system – processes that stay zombies for a long time are generally an error and cause a resource leak.

The term zombie process derives from the common definition of zombie — an undead person. In the term's metaphor, the child process has "died" but has not yet been "reaped". Also, unlike normal processes, the kill command has no effect on a zombie process.

Zombie processes should not be confused with orphan processes: an orphan process is a process that is still executing, but whose parent has died. These do not remain as zombie processes; instead, (like all orphaned processes) they are adopted by init (process ID 1), which waits on its children. The result is that a process that is both a zombie and an orphan will be reaped automatically.

 

僵屍進程查看

 

查看系統裡面有那些僵屍進程,有很多方法,例如top命令,ps命令等

clip_image001

另外,使用ps和grep命令結合也能查看僵屍進程,當然有非常多的形式,如下所。

[root@mylnx01 ~]# ps aux | grep Zs |  grep -v grep
oracle    2002  0.0  0.0      0     0 ?        Zs   02:44   0:00 [sh] <defunct>
oracle    2013  0.0  0.0      0     0 ?        Zs   02:46   0:00 [sh] <defunct>
[root@mylnx01 ~]# 
 
 
[root@mylnx01 ~]# ps -ef | grep defunct
oracle    2002  4788  0 02:44 ?        00:00:00 [sh] <defunct>
oracle    2013  4788  0 02:46 ?        00:00:00 [sh] <defunct>
[root@mylnx01 ~]# 
 
[root@mylnx01 ~]# ps -A -ostat,ppid,pid,cmd | grep -e '^[Zz]'
Zs    4788  2002 [sh] <defunct>
Zs    4788  2013 [sh] <defunct>
[root@mylnx01 ~]# 

 

查看僵屍進程的個數命令

[root@mylnx01 ~]# ps -ef | grep defunct | grep -v grep | wc -l
 
2

 

 

僵屍進程查殺

僵屍進程的查殺有時候是一個頭痛的問題,僵屍進程有時候很殺不掉,有時候還不能亂殺。

clip_image002

要殺掉僵屍進程,一般有兩個方法:

1:找到該defunct僵屍進程的父進程,將該進程的父進程殺掉,則此defunct進程將自動消失

2:重啟伺服器。

 

查看僵屍進程並殺掉

ps -ef | grep defunct | grep -v grep | awk {print "kill -9 " $2,$3}

一般情況下,不建議莽撞的kill掉這些僵屍進程,還是檢查一下具體原因後,根據具體情況再做查殺,如下所示。

[root@mylnx01 ~]# ps -ef | grep defunct
oracle    2002  4788  0 02:44 ?        00:00:00 [sh] <defunct>
oracle    2013  4788  0 02:46 ?        00:00:00 [sh] <defunct>
root     12348 10441  0 12:18 pts/11   00:00:00 grep defunct
[root@mylnx01 ~]# cat /proc/2002/stack
[<ffffffff8105b9f5>] do_exit+0x67d/0x696
[<ffffffff8105baae>] sys_exit_group+0x0/0x1b
[<ffffffff8105bac5>] sys_exit_group+0x17/0x1b
[<ffffffff81011db2>] system_call_fastpath+0x16/0x1b
[<ffffffffffffffff>] 0xffffffffffffffff
[root@mylnx01 ~]# cat /proc/2013/stack
[<ffffffff8105b9f5>] do_exit+0x67d/0x696
[<ffffffff8105baae>] sys_exit_group+0x0/0x1b
[<ffffffff8105bac5>] sys_exit_group+0x17/0x1b
[<ffffffff81011db2>] system_call_fastpath+0x16/0x1b
[<ffffffffffffffff>] 0xffffffffffffffff
[root@mylnx01 ~]# cat /proc/4788/stack
[<ffffffff811de86e>] sys_semtimedop+0x68b/0x7e7
[<ffffffff81011db2>] system_call_fastpath+0x16/0x1b
[<ffffffffffffffff>] 0xffffffffffffffff
[root@mylnx01 ~]# 

 

[root@mylnx01 ~]# lsof -p 4788
COMMAND  PID   USER   FD   TYPE DEVICE      SIZE     NODE NAME
oracle  4788 oracle  cwd    DIR  253,6      4096  7880901 /u01/app/oracle/product/10.2.0/db_1/dbs
oracle  4788 oracle  rtd    DIR  253,0      4096        2 /
oracle  4788 oracle  txt    REG  253,6 104559054  7884256 /u01/app/oracle/product/10.2.0/db_1/bin/oracle
oracle  4788 oracle  DEL    REG    0,4            3211268 /SYSVdf6790e8
oracle  4788 oracle  mem    REG  253,0    143600  8421721 /lib64/ld-2.5.so
oracle  4788 oracle  mem    REG  253,0   1722304  8421722 /lib64/libc-2.5.so
oracle  4788 oracle  mem    REG  253,0    615136  8421739 /lib64/libm-2.5.so
oracle  4788 oracle  mem    REG  253,0     23360  8421607 /lib64/libdl-2.5.so
oracle  4788 oracle  mem    REG  253,0    145824  8421724 /lib64/libpthread-2.5.so
oracle  4788 oracle  mem    REG  253,0    114352  8421738 /lib64/libnsl-2.5.so
oracle  4788 oracle  mem    REG  253,0     53880  8421403 /lib64/libnss_files-2.5.so
oracle  4788 oracle  mem    CHR    1,5               4603 /dev/zero
oracle  4788 oracle  mem    REG  253,0      3768 10426606 /usr/lib64/libaio.so.1.0.1
oracle  4788 oracle  mem    REG  253,6      1552  7893073 /u01/app/oracle/product/10.2.0/db_1/dbs/hc_epps.dat
oracle  4788 oracle  mem    REG  253,6   3796601  7888182 /u01/app/oracle/product/10.2.0/db_1/lib/libnnz10.so
oracle  4788 oracle  mem    REG  253,6    123345  7885115 /u01/app/oracle/product/10.2.0/db_1/lib/libdbcfg10.so
oracle  4788 oracle  mem    REG  253,6     64041  7887888 /u01/app/oracle/product/10.2.0/db_1/lib/libclsra10.so
oracle  4788 oracle  mem    REG  253,6  11385162  7883147 /u01/app/oracle/product/10.2.0/db_1/lib/libjox10.so
oracle  4788 oracle  mem    REG  253,6    516097  7887854 /u01/app/oracle/product/10.2.0/db_1/lib/libocrutl10.so
oracle  4788 oracle  mem    REG  253,6    691049  7887853 /u01/app/oracle/product/10.2.0/db_1/lib/libocrb10.so
oracle  4788 oracle  mem    REG  253,6    681761  7887852 /u01/app/oracle/product/10.2.0/db_1/lib/libocr10.so
oracle  4788 oracle  mem    REG  253,6      8545  7885226 /u01/app/oracle/product/10.2.0/db_1/lib/libskgxn2.so
oracle  4788 oracle  mem    REG  253,6   1772385  7887887 /u01/app/oracle/product/10.2.0/db_1/lib/libhasgen10.so
oracle  4788 oracle  mem    REG  253,6    177809  7884216 /u01/app/oracle/product/10.2.0/db_1/lib/libskgxp10.so
oracle  4788 oracle    0r   CHR    1,3               4601 /dev/null
oracle  4788 oracle    1r   CHR    1,3               4601 /dev/null
oracle  4788 oracle    2w   REG  253,6      1447  7995467 /u01/app/oracle/admin/epps/bdump/epps_psp0_4788.trc
oracle  4788 oracle    3r   CHR    1,3               4601 /dev/null
oracle  4788 oracle    4r   CHR    1,3               4601 /dev/null
oracle  4788 oracle    5w   REG  253,6       663  1638412 /u01/app/oracle/admin/epps/udump/epps_ora_4784.trc (deleted)
oracle  4788 oracle    6w   REG  253,6     30440  7995465 /u01/app/oracle/admin/epps/bdump/alert_epps.log.20150904 (deleted)
oracle  4788 oracle    7u   REG  253,6         0  6930433 /u01/app/oracle/product/10.2.0/db_1/dbs/lkinstepps (deleted)
oracle  4788 oracle    8w   REG  253,6     30440  7995465 /u01/app/oracle/admin/epps/bdump/alert_epps.log.20150904 (deleted)
oracle  4788 oracle    9u   REG  253,6      1552  7893073 /u01/app/oracle/product/10.2.0/db_1/dbs/hc_epps.dat
oracle  4788 oracle   10r   CHR    1,5               4603 /dev/zero
oracle  4788 oracle   11r   REG  253,6    849408  7887921 /u01/app/oracle/product/10.2.0/db_1/rdbms/mesg/oraus.msb
oracle  4788 oracle   12r   CHR    1,5               4603 /dev/zero
oracle  4788 oracle   13u   REG  253,6      1552  7893073 /u01/app/oracle/product/10.2.0/db_1/dbs/hc_epps.dat
oracle  4788 oracle   14uR  REG  253,6        24  7893074 /u01/app/oracle/product/10.2.0/db_1/dbs/lkEPPS
oracle  4788 oracle   15r   REG  253,6    849408  7887921 /u01/app/oracle/product/10.2.0/db_1/rdbms/mesg/oraus.msb

查看僵屍進程的父進程,發現是對應的是ORACLE裡面PSPO進程,關於這個進程,我也沒有把握是否可以KIll掉。所以選擇重啟伺服器比較保險一點。

clip_image003

 

 

參考資料:

https://en.wikipedia.org/wiki/Zombie_process

http://linux.alai.net/viewblog.php?id=48189

您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • PL/SQL是Oracle開發的主要工具,安裝很簡單,在官網 “https://www.allroundautomations.com/plsqldev.html” 選擇合適的版本,也有多國語言包,下載安裝即可,運行的時候輸入用戶名/密碼/資料庫,即可連接 ...
  • "應用程式開發"下的"SQL Developer"雙擊不可用,出現“Windows正在查找SQLDEVELOPER.BAT"的提示,如下圖: 搜索博客園之後,找到:http://www.cnblogs.com/OnlyCT/p/4665666.html 大概明白了原因,Oracle自帶的SQL De ...
  • 測試機上裝入數據 發現中文欄位全部變成???????,初步判斷為字元集問題 更改 UPDATE sys.props$ SET VALUE$='WE8ISO8859P1' where name like 'NLS%' and value$='ZHS16GBK'; commit; 後發現sqlldr採集 ...
  • 場景 前些天遇到一個問題,要往線上資料庫中數據量比較大的表格裡添加新的欄位,以及賦上預設值, 執行的時間比較長,如果直接在原表格的基礎上直接執行sql,害怕會將表格甚至是資料庫弄成死鎖。 和團隊兄弟聊了聊找到了一種辦法,不知道的也可以借鑒一下。 解決辦法 複製表結構到臨時表 CREATE TABLE ...
  • <!--?xml version="1.0" encoding="UTF-8" standalone="no"?--> 1.數據分析和數據挖掘聯繫和區別 聯繫:都是搞數據的 區別:數據分析偏統計,可視化,出報表和報告,需要較強的表達能力。數據挖掘偏演算法,重模型,需要很深的代碼功底,要碼代碼,很多= ...
  • 原創文章,轉載請註明。時間:2016-03-31 問題:cpu負載過高,達到36。 現象:通過mysqladmin -uroot -p processlist 查看到大量如下信息: Sending data select * from `rep_corp_vehicle_online_count` ...
  • Oracle安裝完成後,在“開始”里找到SQL Plus運行,要求輸入帳號和密碼,用system/密碼連接。 1、Oracle里有一個預設的scott賬戶密碼tiger,用該賬戶連接: CONN 用戶名/密碼; eg:CONN scott/tiger; 2、scott賬戶預設是鎖定的,需要進行解鎖: ...
  • jetty作為一款小型的web容器用處很大,因為其小巧強大,經常作為嵌入式的組件處理http交互。 Jetty 作為一個獨立的 Servlet 引擎可以獨立提供 Web 服務,但是它也可以與其他 Web 應用伺服器集成,所以它可以提供基於兩種協議工作,一個是 HTTP,一個是 AJP 協議,本文介紹 ...
一周排行
    -Advertisement-
    Play Games
  • 示例項目結構 在 Visual Studio 中創建一個 WinForms 應用程式後,項目結構如下所示: MyWinFormsApp/ │ ├───Properties/ │ └───Settings.settings │ ├───bin/ │ ├───Debug/ │ └───Release/ ...
  • [STAThread] 特性用於需要與 COM 組件交互的應用程式,尤其是依賴單線程模型(如 Windows Forms 應用程式)的組件。在 STA 模式下,線程擁有自己的消息迴圈,這對於處理用戶界面和某些 COM 組件是必要的。 [STAThread] static void Main(stri ...
  • 在WinForm中使用全局異常捕獲處理 在WinForm應用程式中,全局異常捕獲是確保程式穩定性的關鍵。通過在Program類的Main方法中設置全局異常處理,可以有效地捕獲並處理未預見的異常,從而避免程式崩潰。 註冊全局異常事件 [STAThread] static void Main() { / ...
  • 前言 給大家推薦一款開源的 Winform 控制項庫,可以幫助我們開發更加美觀、漂亮的 WinForm 界面。 項目介紹 SunnyUI.NET 是一個基於 .NET Framework 4.0+、.NET 6、.NET 7 和 .NET 8 的 WinForm 開源控制項庫,同時也提供了工具類庫、擴展 ...
  • 說明 該文章是屬於OverallAuth2.0系列文章,每周更新一篇該系列文章(從0到1完成系統開發)。 該系統文章,我會儘量說的非常詳細,做到不管新手、老手都能看懂。 說明:OverallAuth2.0 是一個簡單、易懂、功能強大的許可權+可視化流程管理系統。 有興趣的朋友,請關註我吧(*^▽^*) ...
  • 一、下載安裝 1.下載git 必須先下載並安裝git,再TortoiseGit下載安裝 git安裝參考教程:https://blog.csdn.net/mukes/article/details/115693833 2.TortoiseGit下載與安裝 TortoiseGit,Git客戶端,32/6 ...
  • 前言 在項目開發過程中,理解數據結構和演算法如同掌握蓋房子的秘訣。演算法不僅能幫助我們編寫高效、優質的代碼,還能解決項目中遇到的各種難題。 給大家推薦一個支持C#的開源免費、新手友好的數據結構與演算法入門教程:Hello演算法。 項目介紹 《Hello Algo》是一本開源免費、新手友好的數據結構與演算法入門 ...
  • 1.生成單個Proto.bat內容 @rem Copyright 2016, Google Inc. @rem All rights reserved. @rem @rem Redistribution and use in source and binary forms, with or with ...
  • 一:背景 1. 講故事 前段時間有位朋友找到我,說他的窗體程式在客戶這邊出現了卡死,讓我幫忙看下怎麼回事?dump也生成了,既然有dump了那就上 windbg 分析吧。 二:WinDbg 分析 1. 為什麼會卡死 窗體程式的卡死,入口門檻很低,後續往下分析就不一定了,不管怎麼說先用 !clrsta ...
  • 前言 人工智慧時代,人臉識別技術已成為安全驗證、身份識別和用戶交互的關鍵工具。 給大家推薦一款.NET 開源提供了強大的人臉識別 API,工具不僅易於集成,還具備高效處理能力。 本文將介紹一款如何利用這些API,為我們的項目添加智能識別的亮點。 項目介紹 GitHub 上擁有 1.2k 星標的 C# ...