[問題] 短暫成為殭屍行程是正常的嗎?[已解決]
開發平台(Platform): (Ex: Win10, Linux, ...)
Linux
編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出)
gcc-6
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
短暫成為殭屍行程是正常的嗎?
餵入的資料(Input):
預期的正確結果(Expected Output):
即使子行程提早結束也不會變成殭屍行程
錯誤結果(Wrong Output):
程式碼(Code):(請善用置底文網頁, 記得排版)
if (pid < 0) {
perror("fork");
exit(EXIT_FAILURE);
}
else if (pid == 0) { // child process
system("sleep 0");
_exit(EXIT_SUCCESS);
}
else if (pid > 0) { // parent process
system("sleep 3"); // 子行程變成殭屍行程
waitpid(pid, &ret, 0); // 順利回收子行程
}
補充說明(Supplement):
上述的實驗就算子行程提早結束了
waitpid 好像還是可以順利回收那個變成殭屍的子行程
這樣產生短暫的殭屍行程是正常的嗎 XDD (抓頭
謝謝
== 已解決 ==
這應該是正常的
Synchronously waiting for the specific child processes in a (specific) order
may leave zombies present longer than the above-mentioned "short period of
time". It is not necessarily a program bug. -- Wikipedia, Zombie process, Sec 2
--
Lorem ipsum dolor sit amet, cons
ectetuer adipiscing elit. Aenean co
mmodo ligula eget dolor. Aenean mas
sa. Cum sociis natoque penatibus et
magnis dis parturient montes, nasce
tur ridiculus mus. Donec quam felis
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.113.68.52
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1508263111.A.BA5.html
※ 編輯: Hazukashiine (140.113.68.52), 10/18/2017 02:44:06
推
10/18 08:31,
8年前
, 1F
10/18 08:31, 1F
→
10/18 08:31,
8年前
, 2F
10/18 08:31, 2F
推
10/18 09:41,
8年前
, 3F
10/18 09:41, 3F
→
10/18 09:42,
8年前
, 4F
10/18 09:42, 4F
→
10/18 09:50,
8年前
, 5F
10/18 09:50, 5F
推
10/18 13:05,
8年前
, 6F
10/18 13:05, 6F
推
10/18 16:29,
8年前
, 7F
10/18 16:29, 7F
→
10/18 16:31,
8年前
, 8F
10/18 16:31, 8F
→
10/18 16:33,
8年前
, 9F
10/18 16:33, 9F
→
10/18 16:33,
8年前
, 10F
10/18 16:33, 10F
→
10/18 16:34,
8年前
, 11F
10/18 16:34, 11F
推
10/18 21:15,
8年前
, 12F
10/18 21:15, 12F