推荐

linux shell 查看进程的可执行程序路径

注:此方法仅在bash下测试有效。

ps -el | grep hello

ls -l /proc/19120/exe | awk '{print $11}'

hello是某程序的名字,ps -el | grep hello 命令把是hello名字进程全部列出来。

然后,加入要查看进程号PID为19120的可执行程序路径,ls -l /proc/19120/exe | awk '{print $11}'

 

写一个脚本获取指定进程名字的绝对路径,该脚本匹配包含参数1的进程名,列出所有进程的可执行程序的路径。

脚本文件psd 如下

  #! /bin/bash
  
   if [ $# -ne 1 ] ; then
       echo "Usage: psd exe"
       exit 1
   fi
  
   for pid in `ps -e | grep $1 | awk '{print $1}'` ;
   do
      echo -n "${pid} "
      ls -l /proc/${pid}/exe | awk '{print $11}'
  done
  

 转自:http://hi.baidu.com/xncehkcfrpjrtue/item/8a0eae10d090b424f7625c73

posted on 2012-10-25 13:49  高华  阅读(11525)  评论(0编辑  收藏  举报

导航