1. 程式人生 > 其它 >Linux根據程序號查詢工作目錄

Linux根據程序號查詢工作目錄

jdk有提供一個檢視當前Java程序的工具 —— jps。
位置在jdk的bin目錄:/jdk1.8.0_281/bin/jps.exe,使用方法如下:

usage: jps [--help]
       jps [-q] [-mlvV] [<hostid>]

Definitions:
    <hostid>:      <hostname>[:<port>]
    -? -h --help -help: Print this help message and exit.

各個引數的解釋:

-q:
Suppress the output of the class name, JAR file name, and arguments   
passed to the main method, producing only a list of local VM identifiers.
只輸出程序號

-m:
Output the arguments passed to the main method. The output may be null for embedded JVMs
輸出傳遞給main方法的引數

-l:
Output the full package name for the application's main class or the full path name   
to the application's JAR file.
輸出主類的全路徑名,或者jar包的全路徑

-v:
Output the arguments passed to the JVM.
輸出 傳遞給jvm虛擬機器的引數

-V:
Output the arguments passed to the JVM through the flags file (the .hotspotrc   
file or the file specified by the -XX:Flags=<filename> argument).
輸出通過flag檔案傳遞到JVM中的引數(.hotspotrc檔案或-XX:Flags=所指定的檔案 

最常用的就是 jps -l了,列出程序號和jar包名,說明文件裡說這個引數能輸出jar的全路徑,實際使用的時候發現
只能輸出jar包的名字,應該是我使用姿勢有問題,最終解決方案如下:

通過`jps -l`命令輸出jar包的程序號和包名  

然後通過`pwdx [程序號]`輸出jar包的絕對路徑

pwdx在這個位置:

[root@VM-0-17-centos server]# type -a pwdx
pwdx is /usr/bin/pwdx

當然,這只是通過jps找到Java的程序,如果想知道某個埠的程序號,可以使用命令lsof -i:[埠號]