Linux 根据PID找到相应应用程序的运行目录

时间:2023-03-09 13:31:02
Linux 根据PID找到相应应用程序的运行目录

1.找到运行程序的PID

# ps aux | grep redis
root            pts/    S+   :   : grep redis
root           ?        Ssl  Aug30   : redis-server *:
# ps aux | grep redis
root            pts/    S+   :   : grep redis
root           ?        Ssl  Aug30   : redis-server *:
# 

不管用ps也好,top也罢,只要能够找到运行程序的PID,例如,上面redis的pid为1782

2.找到程序的路径

# /exe
lrwxrwxrwx.  root root  8月  : /proc//exe -> /usr/local/bin/redis-server

根据PID则可以在/proc/PID/exe 找到程序所在的目录