1、执行pwdx PID命令,用来显示进程的当前工作目录和可执行文件的路径。
2、执行ll /proc/PID/cwd或者ls -l /proc/PID/exe命令,也可以查看进程的路径。/proc文件系统是一个虚拟文件系统,它为内核和进程之间提供了一个接口。对于每个进程,/proc下都有一个以PID命名的目录。这个目录下的cwd符号链接指向了进程当前的工作目录,而exe符号链接则指向了执行程序的绝对路径。
root@ubuntu-test-rongheceshi:~/share/fused_localization_pkg_ubuntu18-x86_64_20240419023903/install# pwdx 3160
3160: /root/share/fused_localization_pkg_ubuntu18-x86_64_20240419023903/install
root@ubuntu-test-rongheceshi:~/share/fused_localization_pkg_ubuntu18-x86_64_20240419023903/install# ll /proc/3160/cwd
lrwxrwxrwx 1 root root 0 Apr 19 03:20 /proc/3160/cwd -> /root/share/fused_localization_pkg_ubuntu18-x86_64_20240419023903/install/
root@ubuntu-test-rongheceshi:~/share/fused_localization_pkg_ubuntu18-x86_64_20240419023903/install# ls -l /proc/3160/exe
lrwxrwxrwx 1 root root 0 Apr 19 03:29 /proc/3160/exe -> /root/share/fused_localization_pkg_ubuntu18-x86_64_20240419023903/install/lib/fused_localization_pkg/fused_localization_node