如何在 Unix/Linux 中获取进程的路径 [英] How do I get the path of a process in Unix / Linux
本文介绍了如何在 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
.
这篇关于如何在 Unix/Linux 中获取进程的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文