2011-03-29 56 views
2

我有一個程序作爲殭屍進程運行。我想調試它。但是我得到了一個gdb錯誤。gdb是否可以附加殭屍程序(<defunct>)?

mobile:/usr/local/ads5/bin# ps axf | grep ads_resolver 
5583 pts/2 S  0:00 ./ads_resolver main.cfg 
5584 pts/2 Zl  0:36 \_ [ads_resolver] <defunct> 

mobile:/usr/local/ads5/bin# gdb ads_resolver 5584 
GNU gdb 6.8-debian 
Copyright (C) 2008 Free Software Foundation, Inc. 
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> 
This is free software: you are free to change and redistribute it. 
There is NO WARRANTY, to the extent permitted by law. Type "show copying" 
and "show warranty" for details. 
This GDB was configured as "i486-linux-gnu"... 
Attaching to program: /usr/local/ads5/bin/ads_resolver, process 5584 
ptrace: Operation not permitted. 
/usr/local/ads5/bin/5584: No such file or directory. 
(gdb) info threads 
No registers. 

有我的代碼,創建殭屍進程:

template < class T> 
int Monitor <T>::Start() 
{ 
    pid_t pid; 
    pid = fork(); 
    if(pid == 0) 
    { 
     IgnoreSignal::IgnoreDaemon(); 
     signal(SIGCHLD,Monitor<T>::ReStart); 

     pid = fork(); 
     if(pid == 0) 
     { 
      IgnoreSignal::IgnoreAll(); 
      T worker; 
      worker.Run(); 
     } 
     while(1) 
     { 
      sleep(60); 
     } 
    } 
    return 0; 
} 
+0

嘗試'須藤gdb',雖然一個解釋你將不得不等待別人有更多的Unix知識的答案。 – 2011-03-30 12:12:44

回答

6

一個殭屍進程已完成執行,但操作系統正在等待家長來調用wait()。這只是一種狀態或標誌 - 該流程不再是「可執行」的存在。

因此,不可能讓gdb連接到一個不再執行的進程,包括殭屍進程。

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

+0

但是,也許你可以附加到家長,並使用'gdb>調用...等待(...)'手動收集它的狀態(和probaby在同一時間搞亂父母的狀態;)) – 2014-10-20 12:24:38