1 senha
Sintaxe: 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
2ls -l /proc/${pid}
Quando o Linux inicia um processo, o sistema criará uma pasta com o nome do PID em /proc. Nessa pasta, haverá informações sobre o nosso processo, incluindo um arquivo chamado exe, que registra o caminho absoluto. ll ou ls –l comando ver.
- O link simbólico cwd é o diretório de execução do processo;
- O link simbólico exe é o caminho absoluto para executar o programa ;
- cmdline é o comando da linha de comando inserido quando o programa está em execução;
- environ registra as variáveis de ambiente quando o processo está em execução;
- O diretório fd é um link simbólico para os arquivos abertos ou usados pelo processo.
Pode ser usado em conjunto com grep. Por
ls -l /proc/${pid} | grep cwd
ls -l /proc/proc/${pid} | grep exe
exemplo, já sabemos que o processo é 13820, então
[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