Linux 根据进程ID查看文件路径(转)

遇到的问题是想要查看进程的启动脚本在哪里,比如自己写的weblogic启动脚本,但忘记放在哪里了,这时候可以用以下方式

1、用ps -ef |grep xxxxx 得到该进程的pid

2、输入ls -l ,结果中 exe链接对应的就是可执行文件的路径
$ ls -l /proc/18283

dr-xr-xr-x 2 root root 0 Jan 21 10:39 attr
-r-------- 1 root root 0 Jan 21 10:39 auxv
-r--r--r-- 1 root root 0 Jan 21 10:14 cmdline
-rw-r--r-- 1 root root 0 Jan 21 10:39 coredump_filter
-r--r--r-- 1 root root 0 Jan 21 10:39 cpuset
lrwxrwxrwx 1 root root 0 Jan 21 10:39 cwd -> /app/script/test
-r-------- 1 root root 0 Jan 21 10:39 environ
lrwxrwxrwx 1 root root 0 Jan 21 10:39 exe -> /bin/bash
dr-x------ 2 root root 0 Jan 21 10:39 fd
-r--r--r-- 1 root root 0 Jan 21 10:39 io
-r-------- 1 root root 0 Jan 21 10:39 limits
-rw-r--r-- 1 root root 0 Jan 21 10:39 loginuid
-r--r--r-- 1 root root 0 Jan 21 10:39 maps
-rw------- 1 root root 0 Jan 21 10:39 mem
-r--r--r-- 1 root root 0 Jan 21 10:39 mounts
-r-------- 1 root root 0 Jan 21 10:39 mountstats
-rw-r--r-- 1 root root 0 Jan 21 10:39 oom_adj
-r--r--r-- 1 root root 0 Jan 21 10:39 oom_score
lrwxrwxrwx 1 root root 0 Jan 21 10:39 root -> /
-r--r--r-- 1 root root 0 Jan 21 10:39 schedstat
-r-------- 1 root root 0 Jan 21 10:39 smaps
-r--r--r-- 1 root root 0 Jan 21 10:14 stat
-r--r--r-- 1 root root 0 Jan 21 10:39 statm
-r--r--r-- 1 root root 0 Jan 21 10:14 status
dr-xr-xr-x 3 root root 0 Jan 21 10:39 task
-r--r--r-- 1 root root 0 Jan 21 10:39 wchan

以下是/proc目录中进程N的信息

/proc/N pid为N的进程信息

/proc/N/cmdline 进程启动命令

/proc/N/cwd 链接到进程当前工作目录

/proc/N/environ 进程环境变量列表

/proc/N/exe 链接到进程的执行命令文件

/proc/N/fd 包含进程相关的所有的文件描述符

/proc/N/maps 与进程相关的内存映射信息

/proc/N/mem 指代进程持有的内存,不可读

/proc/N/root 链接到进程的根目录

/proc/N/stat 进程的状态

/proc/N/statm 进程使用的内存的状态

/proc/N/status 进程状态信息,比stat/statm更具可读性

转自 http://blog.csdn.net/zheng0518/article/details/42964913

原文地址:https://www.cnblogs.com/SamuelSun/p/5026291.html