IT. POST LIST

POST ALL LABEL

defunct(좀비) process 죽이기 feat. scripts

By 때찌때찌맴매 - 12월 07, 2017

** top으로 프로세스 현황을 보면 가끔 좀비 프로세스가 있습니다. 해당 포스팅은 좀비 프로세스 확인 및 제거를 진행합니다.
 [root@localhost ]# top

top - 13:21:53 up 362 days, 12:51,  2 users,  load average: 0.36, 0.51, 0.60
Tasks: 544 total,   1 running, 541 sleeping,   0 stopped,   2 zombie
Cpu0  :  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Cpu1  :  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Cpu2  :  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Cpu3  :  2.0%us,  0.3%sy,  0.0%ni, 97.7%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Cpu4  :  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Cpu5  :  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Cpu6  :  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Cpu7  : 10.4%us,  0.7%sy,  0.0%ni, 88.3%id,  0.0%wa,  0.0%hi,  0.7%si,  0.0%st
Mem:   8017812k total,  5458432k used,  2559380k free,   586348k buffers
Swap:  4194300k total,     9648k used,  4184652k free,  1795476k cached

좀비 찾기

** 명령어
ps -ef | grep defunct | grep -v grep
** 실행예시
 [root@localhost ]# ps -ef | grep defunct | grep -v grep
root      8019  8017  0 12:01 ?        00:00:00 [unknown-error-t] 
root      8020  8017  0 12:01 ?        00:00:00 [unknown-error-t] 

좀비 죽이기

** 명령어
[root@localhost ]# kill -9 8017
root      8019  8017  0 12:01 ?        00:00:00 [unknown-error-t] 
root      8020  8017  0 12:01 ?        00:00:00 [unknown-error-t] 

** 좀비 모두 죽이기

ps -ef | grep defunct | awk '{print $3}' | xargs kill -9

스크립트 작성 (cron 등록후 사용해도됨)

[root@localhost]# vi zombie_kill.sh

#! /bin/bash
date="$(date "+%Y-%m-%d_%H:%M:%S")"
log_dir="경로입력"
zombie_check=`ps -ef | grep defunct | grep -v grep | grep -v "\[sh\]"| wc -l`
if [ $zombie_check == '0'   ]; then
    exit 0;
else
    echo "==============================================================" >> /$log_dir/zombie_kill.txt
    ps -ef | grep defunct | grep -v grep | grep -v "\[sh\]" >> /{path}/zombie_kill.txt
    ps -ef | grep defunct | grep -v grep | grep -v "\[sh\]" | awk '{print $3}' | xargs kill -9
    echo "kill zombie process_$date " >> /$log_dir/zombie_kill.txt

    if [ $zombie_check == '0' ]; then
        exit 0;
    else
        /bin/sh /$log_dir/zombie_kill.sh
    fi
fi

로그 확인

[root@localhost ]# cat zombie_kill.txt

==============================================================
root      8019  8017  0 12:01 ?        00:00:00 [unknown-error-t] 
root      8020  8017  0 12:01 ?        00:00:00 [unknown-error-t] 
kill zombie process_2017-12-07_13:38:01

  • Share:

You Might Also Like

0 개의 댓글