java 殺掉 linux下進程和進程的子孫進程

String command= "disspid=$(ps -ef | grep "
        +jobname
        +" | grep -v 'grep' |grep root | awk '{ print $2}' | sort -r | sed -n '1 p');" +
        "for i in  $(pstree -p ${disspid:=999999999999999999} |grep -Po '(?<=\\050)[^\\051]+');" +
        "do kill $i;done;";
logger.info("kill job command : {}",command);
String[] cmdA = { "/bin/sh", "-c", command };
process = Runtime.getRuntime().exec(cmdA);

經過pstree 找到進程全部子孫進程的pid  而後kill掉進程

相關文章
相關標籤/搜索