天天看點

linux訓練python出現killed_Linux 檢視程序被殺死的詳情

運作寫的不太完善的爬蟲程式, 未限制任務隊列大小, 再加上本子配置不高, 爬取網站到第3層大半時, 記憶體不足了...

程序運作太猛, 導緻系統 out of memory, 那麼此程序被系統的oom killer殺死.

此時終端顯示 "Killed" 或 "已殺死".

檢視相關資訊的指令:

dmesg | egrep -i -B100 'killed process'

或:

egrep -i 'killed process' /var/log/messages

egrep -i -r 'killed process' /var/log

或:

journalctl -xb | egrep -i 'killed process'

結果類似這樣:

4月 07 10:48:58 arch kernel: Out of memory: Kill process 1245 (python) score 685 or sacrifice child

4月 07 10:48:58 arch kernel: Killed process 1245 (python) total-vm:3519016kB, anon-rss:2453976kB, file-rss:0kB

參考:

http://stackoverflow.com/questions/726690/who-killed-my-process-and-why

http://stackoverflow.com/questions/624857/finding-which-process-was-killed-by-linux-oom-killer

http://unix.stackexchange.com/questions/10077/where-can-i-see-a-list-of-kernel-killed-processes