您的位置:首页 > 运维架构 > Shell

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

2012-10-25 13:49 357 查看
注:此方法仅在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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: