神奇的Java'僵尸'进程问题

2018-09-14  本文已影响0人  landon30

神奇的"僵尸"进程问题(java defunct)

现象描述

艰难的排查过程1-尝试复现

import java.util.concurrent.TimeUnit;

public class Defunct {
    public static void main(String[] args) {
        while (true) {
            System.out.println("test defunct");

            try {
                TimeUnit.SECONDS.sleep(30);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
#!/bin/bash

nohup java -cp defunct.jar Defunct &

echo "$!"
echo "$!" > pid
#!/bin/bash

nohup java -cp defunct.jar Defunct &

echo "$!"
echo "$!" > pid

tail -f nohup.out

#!/bin/bash

pid=`cat pid`
echo $pid

kill $pid

艰难的排查过程2-游戏服务器尝试复现

艰难的排查过程3-各种思考、查阅资料

神奇的ctrl+z 复现测试代码defunct

[xx@achilles deploy_defunct]$ sh start_tail.sh 
3974
nohup: appending output to `nohup.out'
defunct2
^Z
[2]+  Stopped                 sh start_tail.sh
[xx@achilles deploy_defunct]$ sh stop.sh
3974
[xx@achilles deploy_defunct]$ jps
4146 Jps
3974 Defunct2
12790 SpursLauncher
3726 SpursLauncher
[xx@achilles deploy_defunct]$ kill -9 3974
[xx@achilles deploy_defunct]$ jps
3974 Defunct2
12790 SpursLauncher
4314 Jps
3726 SpursLauncher
[xx@achilles deploy_defunct]$ ps -el | grep 3974
0 Z   500  3974  3973  0  80   0 -     0 exit   pts/4    00:00:00 java <defunct>
[xx@achilles deploy_defunct]$ ps -el | grep 3974
0 Z   500  3974  3973  0  80   0 -     0 exit   pts/4    00:00:00 java <defunct>
[xx@achilles deploy_defunct]$ fg
sh start_tail.sh
^C
[xx@achilles deploy_defunct]$ ps -el | grep 3974

神奇的ctrl+z 复现游戏服务器defunct

[xx@achilles spurs-2]$ sh start.sh
......
^Z
[1]+  Stopped                 sh start.sh
[xx@achilles spurs-2]$ sh shutdown.sh 
^C
[xx@achilles spurs-2]$ jps
9667 SpursLauncher
9796 Jps
[xx@achilles spurs-2]$ ll /proc/9667 | grep cwd
lrwxrwxrwx  1 xx xx 0 Dec  5 17:32 cwd -> /data/home/user00/xx/achilles/backend/spurs-2

[xx@achilles spurs-2]$ ps -el | grep 9667
0 T   500  9667  9666  7  80   0 - 1442848 signal pts/6  00:00:07 java
[xx@achilles spurs-2]$ ps -el | grep 9666
0 T   500  9666  8959  0  80   0 - 26521 signal pts/6    00:00:00 sh
0 T   500  9667  9666  7  80   0 - 1442848 signal pts/6  00:00:07 java
0 T   500  9669  9666  0  80   0 - 25241 signal pts/6    00:00:00 tail
[xx@achilles spurs-2]$ jstack 9667
^C
[xx@achilles spurs-2]$ kill -9 9667
[xx@achilles spurs-2]$ ps -el | grep 9667
0 Z   500  9667  9666  1  80   0 -     0 exit   pts/6    00:00:07 java <defunct>
[xx@achilles spurs-2]$ fg
sh start.sh
^C
[xx@achilles spurs-2]$ ps -el | grep 9666
[xx@achilles spurs-2]$ ps -el | grep 9667

总结1

总结2

总结3

总结4

参考

上一篇下一篇

猜你喜欢

热点阅读