如何确定进程二进制文件的路径?

Sup*_*mbo 33 process

有没有办法找出进程启动的目录/磁盘位置?我知道 /proc 挂载,但不知道在哪里查看它的内部。

Egi*_*gil 40

/proc方法是检查exe在对应的PID的目录链接。

让我们举一个例子update-notifier

找到 pid,在本例中为15421

egil@gud:~$ ps x | grep update-notifier
 2405 pts/4    S+     0:00 grep update-notifier
15421 ?        Sl     0:00 update-notifier
Run Code Online (Sandbox Code Playgroud)

查找符号链接:

egil@gud:~$ file /proc/15421/exe
/proc/15421/exe: symbolic link to `/usr/bin/update-notifier'
Run Code Online (Sandbox Code Playgroud)


N.N*_*.N. 16

也许which这就是你要找的。例如,在我的系统上

which firefox 
Run Code Online (Sandbox Code Playgroud)

返回

/usr/bin/firefox
Run Code Online (Sandbox Code Playgroud)

另请参阅查找在 Solaris、Ubuntu、Suse 或 Redhat Linux 上运行的应用程序的路径

  • `which` 很酷,但它只返回 $PATH 中的程序。如果我运行`RandomProgramIDownloadedToErisKnowsWhere.bin`,这将没有多大用处。 (6认同)

Lek*_*eyn 7

如果您有可用的进程 ID,您可以使用:

readlink -f /proc/$pid/exe
Run Code Online (Sandbox Code Playgroud)

(替换$pid为进程的进程ID)

如果流程不属于您,则您必须将其放在sudo前面。

确定命令位置的示例firefox

  1. 的输出ps ax -o pid,cmd | grep firefox

    22831 grep --color=auto firefox
    28179 /usr/lib/firefox-4.0.1/firefox-bin
    
    Run Code Online (Sandbox Code Playgroud)
  2. 28179 是进程 ID,因此您必须运行:

    readlink -f /proc/28179/exe
    
    Run Code Online (Sandbox Code Playgroud)

    输出:

    /usr/bin/firefox
    
    Run Code Online (Sandbox Code Playgroud)

  • 你可以用 `/proc/$pid/exe` 做一些很酷的事情,如果二进制文件被意外删除,你可以用: `dd if=/proc/$pid/exe of=restored-binary` 恢复它 (2认同)