defunct(좀비) process 죽이기

top으로 프로세스 현황을 보면 가끔 좀비 프로세스가 있는 경우가 있다. (아래 예시에서는 두번째 줄 마지막에 1 zombie)

[root@jmnote ~]# top
top - 22:01:31 up 97 days, 17:08,  1 user,  load average: 0.00, 0.00, 0.00
Tasks: 118 total,   3 running, 114 sleeping,   0 stopped,   1 zombie
Cpu(s):  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:   1048576k total,   990160k used,    58416k free,   180060k buffers
Swap:  2031608k total,    48520k used,  1983088k free,   203936k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
    1 root      15   0 10368  544  512 S  0.0  0.1   0:00.12 init
    2 root      RT  -5     0    0    0 S  0.0  0.0   0:03.16 migration/0
    3 root      34  19     0    0    0 S  0.0  0.0   0:00.00 ksoftirqd/0
    4 root      RT  -5     0    0    0 S  0.0  0.0   0:00.00 watchdog/0

좀비 찾기

찾기
ps -ef | grep defunct | grep -v grep
실행예시
[root@jmnote ~]# ps -ef | grep defunct | grep -v grep
root     17107 21899  0 Feb25 ?        00:00:00 [myagent] <defunct>
testuser 21207 21205  0 Feb26 ?        00:00:00 [check_service.sh] <defunct>

좀비 모두 죽이기

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

좀비 수 확인

명령어
top -b -n 1 | grep zombie
ps -ef | grep defunct | grep -v grep | wc -l
실행예시
[root@jmnote ~]# top -b -n 1 | grep zombie
Tasks: 139 total,   1 running, 136 sleeping,   0 stopped,   2 zombie
[root@jmnote ~]# ps -ef | grep defunct | grep -v grep | wc -l
2

안죽는 좀비 죽이기

[root@jmnote ~]# ps -ef | grep defunct | grep -v grep
testuser 10668 10667  0 Apr04 ?        00:00:00 [myscript.sh] <defunct>
→ 20833 프로세스가 좀비 상태
[root@jmnote ~]# kill -9 10668
[root@jmnote ~]# ps -ef | grep defunct | grep -v grep
testuser 10668 10667  0 Apr04 ?        00:00:00 [myscript.sh] <defunct>
→ 죽여도 안 죽음. 좀비.

부모 프로세스 확인 후 조치

[root@jmnote ~]# ps -ef | grep 10667 | grep -v grep
testuser 10667 21229  0 Apr04 ?        00:00:00 crond
testuser 10668 10667  0 Apr04 ?        00:00:00 [myscript.sh] <defunct>
testuser 10689 10667  0 Apr04 ?        00:00:00 /usr/sbin/sendmail -FCronDaemon
→ 부모 프로세스는 crond (10667)
[root@jmnote ~]# ps -ef | grep 21229 | grep -v grep
testuser 10667 21229  0 Apr04 ?        00:00:00 crond
root     21229     1  0 Feb27 ?        00:00:02 crond
→ 조부모 프로세스는 root의 crond (21229)

조부모 프로세스(21229)는 그냥 두고 부모 프로세스(10667)만 죽이면 된다..

[root@jmnote ~]# kill -9 10667
[root@jmnote ~]# ps -ef | grep defunct | grep -v grep
→ 좀비 제거 완료.[1]

여기까지만 해도 되지만 뭔가 찜찜하니 crond 재시작

[root@jmnote ~]# service crond restart
Stopping crond:                                            [  OK  ]
Starting crond:                                            [  OK  ]

http://jmnote.com/wiki/안죽는좀비프로세스죽이기 에서 가져옴

댓글 남기기

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Videos, Slideshows and Podcasts by Cincopa Wordpress Plugin