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:[端口号]

原创文章,作者:6024010,如若转载,请注明出处:https://blog.ytso.com/245095.html

(0)
上一篇 2022年4月18日
下一篇 2022年4月18日

相关推荐

发表回复

登录后才能评论