Linux中通过进程ID获取程序的启动路径

shell脚本如下:

#!/bin/sh

 
if [ "0$1" == "0" ]; then
  echo "Usage: $0 PID";exit 1;
fi
 
if [[ $1 =~ "^[0-9]*$" ]]; then
  num=`ps -ef|grep -i $1|grep -v grep|grep -v $0|wc -l`
  if [ $num -gt "1" ]; then
    echo "Get too many process, please look: /proc/$1";exit 1;
  fi
  ps -ef|grep -i $1|grep -v grep|grep -v $0|awk '{print $2,system("ls -l /proc/"$2)}'|grep cwd
else
  echo "Usage: $0 PID";exit 1;
fi
exit 0
 

发表评论

电子邮件地址不会被公开。 必填项已用*标注

机器人检查 *