前言:前段时间在做变更的时候学到了一个命令叫做
pwdx
,可以用来查看某个进程当初启动时的工作目录,后面去搜集了相关资料,发现该命令原理其实就是读/proc/进程号/cwd,这个cwd(Current Working Directory)就是进程工作目录的软链接。
以下用tail -f 命令,然后查看该命令的目录/proc/pid的内容
[root@Test ~]# cd /proc/910/
[root@Test 910]# ls
arch_status comm fd map_files ns personality smaps task
attr coredump_filter fdinfo maps numa_maps projid_map smaps_rollup timens_offsets
autogroup cpu_resctrl_groups gid_map mem oom_adj root stack timers
auxv cpuset io mountinfo oom_score sched stat timerslack_ns
cgroup cwd ksm_merging_pages mounts oom_score_adj schedstat statm uid_map
clear_refs environ limits mountstats pagemap sessionid status wchan
cmdline exe loginuid net patch_state setgroups syscall
[root@Test 910]# ll
总用量 0
-r--r--r-- 1 root root 0 3月 8 15:47 arch_status
dr-xr-xr-x 2 root root 0 3月 8 15:47 attr
-rw-r--r-- 1 root root 0 3月 8 15:47 autogroup
-r-------- 1 root root 0 3月 8 15:47 auxv
-r--r--r-- 1 root root 0 3月 8 15:47 cgroup
--w------- 1 root root 0 3月 8 15:47 clear_refs
-r--r--r-- 1 root root 0 3月 8 15:47 cmdline
-rw-r--r-- 1 root root 0 3月 8 15:47 comm
-rw-r--r-- 1 root root 0 3月 8 15:47 coredump_filter
-r--r--r-- 1 root root 0 3月 8 15:47 cpu_resctrl_groups
-r--r--r-- 1 root root 0 3月 8 15:47 cpuset
lrwxrwxrwx 1 root root 0 3月 8 15:47 cwd -> /root
-r-------- 1 root root 0 3月 8 15:47 environ
lrwxrwxrwx 1 root root 0 3月 8 15:47 exe -> /usr/bin/tail
dr-x------ 2 root root 0 3月 8 15:47 fd
dr-xr-xr-x 2 root root 0 3月 8 15:47 fdinfo
-rw-r--r-- 1 root root 0 3月 8 15:47 gid_map
-r-------- 1 root root 0 3月 8 15:47 io
-r-------- 1 root root 0 3月 8 15:47 ksm_merging_pages
-r--r--r-- 1 root root 0 3月 8 15:47 limits
-rw-r--r-- 1 root root 0 3月 8 15:47 loginuid
dr-x------ 2 root root 0 3月 8 15:47 map_files
-r--r--r-- 1 root root 0 3月 8 15:47 maps
-rw------- 1 root root 0 3月 8 15:47 mem
-r--r--r-- 1 root root 0 3月 8 15:47 mountinfo
-r--r--r-- 1 root root 0 3月 8 15:47 mounts
-r-------- 1 root root 0 3月 8 15:47 mountstats
dr-xr-xr-x 51 root root 0 3月 8 15:47 net
dr-x--x--x 2 root root 0 3月 8 15:47 ns
-r--r--r-- 1 root root 0 3月 8 15:47 numa_maps
-rw-r--r-- 1 root root 0 3月 8 15:47 oom_adj
-r--r--r-- 1 root root 0 3月 8 15:47 oom_score
-rw-r--r-- 1 root root 0 3月 8 15:47 oom_score_adj
-r-------- 1 root root 0 3月 8 15:47 pagemap
-r-------- 1 root root 0 3月 8 15:47 patch_state
-r-------- 1 root root 0 3月 8 15:47 personality
-rw-r--r-- 1 root root 0 3月 8 15:47 projid_map
lrwxrwxrwx 1 root root 0 3月 8 15:47 root -> /
-rw-r--r-- 1 root root 0 3月 8 15:47 sched
-r--r--r-- 1 root root 0 3月 8 15:47 schedstat
-r--r--r-- 1 root root 0 3月 8 15:47 sessionid
-rw-r--r-- 1 root root 0 3月 8 15:47 setgroups
-r--r--r-- 1 root root 0 3月 8 15:47 smaps
-r--r--r-- 1 root root 0 3月 8 15:47 smaps_rollup
-r-------- 1 root root 0 3月 8 15:47 stack
-r--r--r-- 1 root root 0 3月 8 15:47 stat
-r--r--r-- 1 root root 0 3月 8 15:47 statm
-r--r--r-- 1 root root 0 3月 8 15:47 status
-r-------- 1 root root 0 3月 8 15:47 syscall
dr-xr-xr-x 3 root root 0 3月 8 15:47 task
-rw-r--r-- 1 root root 0 3月 8 15:47 timens_offsets
-r--r--r-- 1 root root 0 3月 8 15:47 timers
-rw-rw-rw- 1 root root 0 3月 8 15:47 timerslack_ns
-rw-r--r-- 1 root root 0 3月 8 15:47 uid_map
-r--r--r-- 1 root root 0 3月 8 15:47 wchan
可见,两个软连接:
cwd -> /root
exe -> /usr/bin/tail
cwd表示该进程的当前工作目录
exe表示该进程执行的二进制文件路径