1 pwdx
语法:pwdx pid
[root@localhost prometheus-2.42.0.linux-amd64]# ps -ef | grep prometheus
root 13820 1361 0 10:56 pts/0 00:00:00 ./prometheus
root 13839 1361 0 10:57 pts/0 00:00:00 grep --color=auto prometheus
[root@localhost prometheus-2.42.0.linux-amd64]# pwdx 13820
13820: /home/qingfeng/soft/prometheus-2.42.0.linux-amd64
2 ls -l /proc/${pid}
Linux在启动一个进程时,系统会在 /proc 下创建一个以PID命名的文件夹,在该文件夹下会有我们的进程的信息,其中包括一个名为exe的文件即记录了绝对路径,通过 ll 或 ls –l 命令即可查看.
- cwd符号链接的是进程运行目录;
- exe符号连接就是执行程序的绝对路径;
- cmdline就是程序运行时输入的命令行命令;
- environ记录了进程运行时的环境变量;
- fd目录下是进程打开或使用的文件的符号连接。
可以结合grep使用,如
ls -l /proc/${pid} | grep cwd
ls -l /proc/proc/${pid} | grep exe
上面已经知道进程好是13820,所以
[root@localhost prometheus-2.42.0.linux-amd64]# ls -l /proc/13820
总用量 0
dr-xr-xr-x. 2 root root 0 3月 7 11:04 attr
-rw-r--r--. 1 root root 0 3月 7 11:04 autogroup
-r--------. 1 root root 0 3月 7 11:04 auxv
-r--r--r--. 1 root root 0 3月 7 11:04 cgroup
--w-------. 1 root root 0 3月 7 11:04 clear_refs
-r--r--r--. 1 root root 0 3月 7 10:56 cmdline
-rw-r--r--. 1 root root 0 3月 7 11:04 comm
-rw-r--r--. 1 root root 0 3月 7 11:04 coredump_filter
-r--r--r--. 1 root root 0 3月 7 11:04 cpuset
lrwxrwxrwx. 1 root root 0 3月 7 10:58 cwd -> /home/qingfeng/soft/prometheus-2.42.0.linux-amd64
-r--------. 1 root root 0 3月 7 11:04 environ
lrwxrwxrwx. 1 root root 0 3月 7 10:56 exe -> /home/qingfeng/soft/prometheus-2.42.0.linux-amd64/prometheus
dr-x------. 2 root root 0 3月 7 10:56 fd
dr-x------. 2 root root 0 3月 7 11:00 fdinfo
-rw-r--r--. 1 root root 0 3月 7 11:04 gid_map
-r--------. 1 root root 0 3月 7 11:04 io
-r--r--r--. 1 root root 0 3月 7 11:04 latency
-r--r--r--. 1 root root 0 3月 7 10:56 limits
-rw-r--r--. 1 root root 0 3月 7 11:04 loginuid
-rw-r--r--. 1 root root 0 3月 7 11:04 make-it-fail
dr-x------. 2 root root 0 3月 7 11:04 map_files
-r--r--r--. 1 root root 0 3月 7 11:00 maps
-rw-------. 1 root root 0 3月 7 11:04 mem
-r--r--r--. 1 root root 0 3月 7 11:04 mountinfo
-r--r--r--. 1 root root 0 3月 7 11:04 mounts
-r--------. 1 root root 0 3月 7 11:04 mountstats
dr-xr-xr-x. 5 root root 0 3月 7 11:04 net
dr-x--x--x. 2 root root 0 3月 7 11:04 ns
-r--r--r--. 1 root root 0 3月 7 11:04 numa_maps
-rw-r--r--. 1 root root 0 3月 7 11:04 oom_adj
-r--r--r--. 1 root root 0 3月 7 11:04 oom_score
-rw-r--r--. 1 root root 0 3月 7 11:04 oom_score_adj
-r--r--r--. 1 root root 0 3月 7 11:04 pagemap
-r--------. 1 root root 0 3月 7 11:04 patch_state
-r--r--r--. 1 root root 0 3月 7 11:04 personality
-rw-r--r--. 1 root root 0 3月 7 11:04 projid_map
lrwxrwxrwx. 1 root root 0 3月 7 11:00 root -> /
-rw-r--r--. 1 root root 0 3月 7 11:04 sched
-r--r--r--. 1 root root 0 3月 7 11:04 schedstat
-r--r--r--. 1 root root 0 3月 7 11:04 sessionid
-rw-r--r--. 1 root root 0 3月 7 11:04 setgroups
-r--r--r--. 1 root root 0 3月 7 11:04 smaps
-r--r--r--. 1 root root 0 3月 7 11:04 stack
-r--r--r--. 1 root root 0 3月 7 10:56 stat
-r--r--r--. 1 root root 0 3月 7 11:04 statm
-r--r--r--. 1 root root 0 3月 7 10:56 status
-r--r--r--. 1 root root 0 3月 7 11:04 syscall
dr-xr-xr-x. 10 root root 0 3月 7 11:00 task
-r--r--r--. 1 root root 0 3月 7 11:04 timers
-rw-r--r--. 1 root root 0 3月 7 11:04 uid_map
-r--r--r--. 1 root root 0 3月 7 11:04 wchan