如何在 Unix/Linux 中获取进程的路径
问题描述:
在 Windows 环境中有一个 API 来获取正在运行的进程的路径.Unix/Linux 中是否有类似的东西?
In Windows environment there is an API to obtain the path which is running a process. Is there something similar in Unix / Linux?
或者在这些环境中是否有其他方法可以做到这一点?
Or is there some other way to do that in these environments?
答
在 Linux 上,符号链接 /proc/
具有可执行文件的路径.使用命令 readlink -f/proc/
获取值.
On Linux, the symlink /proc/<pid>/exe
has the path of the executable. Use the command readlink -f /proc/<pid>/exe
to get the value.
在 AIX 上,此文件不存在.您可以比较 cksum
和 cksum/proc/
.
On AIX, this file does not exist. You could compare cksum <actual path to binary>
and cksum /proc/<pid>/object/a.out
.