注:此方法僅在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