ptrace:附加到殭屍行程時不允許操作

ptrace:附加到殭屍行程時不允許操作

我遇到了一種可重現的情況,當我重建套件時,編譯器實例進入殭屍狀態,但gdb不允許我附加:

serenity ~ # ps ax | grep defunct
11351 pts/1    Z+     0:00 [x86_64-pc-linux] <defunct>
21838 pts/5    S+     0:00 grep --colour=auto defunct
serenity ~ # gdb -p 11351
GNU gdb (Gentoo 7.10.1 vanilla) 7.10.1
[snip]
Attaching to process 11351
warning: process 11351 is a zombie - the process has already terminated
ptrace: Operation not permitted.
(gdb) 

這個問題表明問題出在proc.sys.kernel.yama.ptrace_scope,或者我可能不是 root,但 sysctl 不存在於我的系統上,並且我以 root 身分運行:

serenity ~ # sysctl -a | grep ptrace
sysctl: reading key "net.ipv6.conf.all.stable_secret"
sysctl: reading key "net.ipv6.conf.default.stable_secret"
sysctl: reading key "net.ipv6.conf.enp4s0.stable_secret"
sysctl: reading key "net.ipv6.conf.lo.stable_secret"
serenity ~ # whoami
root
serenity ~ # 

作為參考,我的內核版本是4.9.16-gentoo.

答案1

正如您的問題輸出中所述,殭屍進程是已完成執行的進程,因此您永遠無法使用 gdb 附加到它 - 現在它只是內核進程表中的一個條目,沒有任何相應的進程或資源,所以gdb 沒有任何東西可以附加。

此行程表條目存在(標記為殭屍)的唯一原因是為了讀取其退出狀態。

相關內容