删除jps命令出现的 “process information unavailable”之类的进程pid文件

如下 图所示,需要把红框中这些显示为unavailable的进程给清除干净

shell脚本内容如下:

#!/bin/bash
#2个参数,参数1:数组,参数2:单个元素;判断单个元素是否在数组中
function is_exists()
{
  array=$1
  for e in ${array[*]}; do
    if test "$2" = "$e"; then
      echo yes
      return
    fi
 done
 echo no
}

unaval_pids=(`jps|grep unavailable|awk '{print $1}'`)
#echo ${#unaval_pids[*]}

pid_files=`(find /tmp -type f -exec ls -lR \{\} \;|grep hsperfdata_|awk '{print $9}')`
for pid_file in ${pid_files[@]}; do
  pid=`echo $pid_file|awk -F '/' '{print $4}'`
  if [ $(is_exists "${unaval_pids[*]}" "$pid") == "yes" ]; then
     rm -f $pid_file
  fi
done

 

posted @ 2021-10-26 13:29  工作随记  阅读(153)  评论(0)    收藏  举报