1 pwdx
Syntax: 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}
When Linux starts a process, the system will create a folder named after the PID under /proc. Under this folder, there will be information about our process, including a file named exe, which records the absolute path. ll or ls –l command to view.
- The cwd symbolic link is the process running directory;
- The exe symbolic link is the absolute path to execute the program ;
- cmdline is the command line command entered when the program is running;
- environ records the environment variables when the process is running;
- The fd directory is a symbolic link to the files opened or used by the process.
It can be used in conjunction with grep. For
ls -l /proc/${pid} | grep cwd
ls -l /proc/proc/${pid} | grep exe
example, we already know that the process is 13820, so
[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