当我执行命令以提供正在运行的进程的 pid 时,它给了我这样的 -
user@machineA:/$ ps -eo pid,command | grep exhibitor | grep java | grep -v grep
1615 java -jar ./exhibitor-1.2.3/lib/exhibitor-1.2.3-jar-with-dependencies.jar --fsconfigdir /opt/exhibitor/conf --hostname machineA
Run Code Online (Sandbox Code Playgroud)
现在我在上面的输出中看到了这条路径 -
./exhibitor-1.2.3/lib/exhibitor-1.2.3-jar-with-dependencies.jar
Run Code Online (Sandbox Code Playgroud)
现在我试图了解这个文件夹在哪里,./exhibitor-1.2.3/因为我无法找到。这个文件夹是否在同一台 ubuntu 机器上?有没有办法找出那个目录在哪里?
我正在运行 Ubuntu 12.04
文件名是相对于 Java 进程尝试访问它时的当前目录的。没有确定的方法可以确定这一点。您可以查看进程的当前目录:
ls -l /proc/1615/cwd
Run Code Online (Sandbox Code Playgroud)
如果该进程仍然打开文件,您将能够轻松找到它的位置。
ls -l /proc/1615/fd
Run Code Online (Sandbox Code Playgroud)
如果由于程序更改了当前目录而无法通过这种方式找到文件,则可以尝试检查父进程的当前目录(如果父进程仍然存在)。使用ps l 1615查看父进程的PID(PPID),然后查看父进程的cwd.
如果失败,可以使用locate命令来搜索具有特定名称的文件。
locate exhibitor-1.2.3-jar-with-dependencies.jar
Run Code Online (Sandbox Code Playgroud)
locate 命令搜索每天晚上更新的索引(或者如果您晚上关闭计算机,则在不同的时间更新),因此如果您最近安装了该文件,则可能找不到这种方式。
无奈之下,可以使用该find命令在目录层次结构中查找该文件。例如,如果您怀疑该文件位于您的主目录下:
find ~ -name exhibitor-1.2.3-jar-with-dependencies.jar
Run Code Online (Sandbox Code Playgroud)
要查看系统目录中的所有位置:
find / -xdev -name exhibitor-1.2.3-jar-with-dependencies.jar
Run Code Online (Sandbox Code Playgroud)