0
當等待子進程終止時,我看到以下代碼中出現異常信號編號(例如50,80或117)。我只從一個特定的子進程中看到了這一點,而且我無法訪問進程源代碼,並且只在某些時候發生。waitpid後來自WTERMSIG宏的不尋常信號編號()
我想知道這些不尋常的值是什麼意思,給出NSIG == 32
,我可以在頭文件或手冊頁中找到一些文檔?
請注意,此代碼運行循環,逐漸發送更多的威脅信號,直到孩子終止。
int status, signal;
if (waitpid(m_procId, &status, WNOHANG) < 0) {
LOGERR << "Failed to wait for process " << name() << ": " <<
strerror(errno) << " (" << errno << ")";
break;
} else if (WIFEXITED(status)) {
m_exitCode = WEXITSTATUS(status);
terminated = true;
LOGINF << "Process " << name() << " terminated with exit code " << m_exitCode;
} else if (WIFSIGNALED(status)) {
signal = WTERMSIG(status); // !!! signal is sometimes 50, 80 or 117 !!!
terminated = true;
LOGINF << "Process " << name() << " terminated by signal " << signal;
} else {
LOGWRN << "Process " << name() << " changed state but did not terminate. status=0x" <<
hex << status;
}
這是運行在OSX 10.8.4,但我也看到它在10.9 GM種子。
編輯修改代碼如下所示,使代碼更健壯,但有時子進程孤立,因爲我認爲循環不足以殺死子進程。
else if (WIFSIGNALED(status)) {
signal = WTERMSIG(status);
if (signal < NSIG) {
terminated = true;
LOGINF << "Process " << name() << " terminated by signal " << signal;
} else {
LOGWRN << "Process " << name() << " produced unusual signal " << signal
<< "; assuming it's not terminated";
}
}
注意這個代碼是這個class的Process::unload()
方法的一部分。
是啊,這肯定是爲「搞笑」的信號值的原因,但是你可以解釋爲什麼'waitpid函數()'將返回'0'和但孩子還活着?我做了處理'0'返回的變化,孩子終止了,但是它需要幾個循環。 – trojanfoe
我也使用'WUNTRACED'標誌'waitpid()',它似乎解決了這個問題。我無法獎勵另外4個小時的獎勵,所以如果我忘了請提醒我。非常感謝您的幫助。 – trojanfoe
很高興幫助! 'waitpid'只會報告停止或已經終止的子節點的狀態(並返回> 0)。這聽起來像你使用'WUNTRACED'已經處理了這個,但是。 – MikeGM