Detailed explanation of the use of the jps command in Java

Introduction to the jps command

jps (Java Virtual Machine Process Status Tool) is a command-line tool provided by JDK that can list the process information of the running Java virtual machine. It can display the execution main class (Main Class, main() function of the Java virtual machine process) The class) name, the unique ID of the local virtual machine (LVMID, Local Virtual Machine Identifier) ​​and other information. Also, the jps command can only display information about the Java processes it has access to.

Although the function of the jps command is relatively simple, it is used very frequently. For the local virtual machine, the unique ID of the local virtual machine is the same as the process ID (PID, Process Identifier) ​​of the operating system. If multiple Java virtual machine processes are started at the same time, a process cannot be determined based on the process name. We just use The jps command displays the function of the main class name to distinguish it.

jps command parameters

Command syntax:

jps [-q] [-mlvV] [hostid]

jps [-help]

Command parameter description:

  • -q: Does not display the main class name, JAR file name and parameters passed to the main method, only the unique ID of the local virtual machine is displayed.
  • -mlvV: We can specify any combination of these parameters.
    • -m: Displays the parameters passed to the main() method when the Java virtual machine starts.
    • -l: Displays the full package name of the main class. If the process executes a JAR file, it also displays the full path of the JAR file.
    • -v: Displays the JVM parameters passed when the Java virtual machine is started.
    • -V: Does not display the main class name, JAR file name and parameters passed to the main method, only the unique ID of the local virtual machine is displayed.
  • hostid: The specified remote host, which can be an ip address and a domain name, or a specific protocol and port. If not specified, the process information of the native Java virtual machine is displayed.
  • -help: Displays help information for the jps command.

Without specifying any arguments, the jps command displays the local virtual machine unique ID for each Java virtual machine process, followed by the main class name or the short form of the JAR file name.

Command display format:

LVMID [ [ classname | JARfilename | "Unknown"] [ arg* ] [ jvmarg* ] ]

All of the outputs are separated by spaces, so when argor jvmargcontains spaces, it may be difficult to distinguish, and you need to pay attention.

jps command example

Display the native Java virtual machine process:

# jps
15729 jar
92153 Jps
90267 Jstat

Display the full package name or JAR file name of the main class:

# jps -l
15729 one-more-1.0.0.RELEASE.jar
112054 sun.tools.jps.Jps
90267 sun.tools.jstat.Jstat

Display the full package name or JAR file name of the main class, and display the JVM arguments:

# jps -lv
15729 one-more-1.0.0.RELEASE.jar -Xmx1g -Xms1g -Xmn512m -XX:SurvivorRatio=4 -XX:MetaspaceSize=256m -XX:+UseG1GC
9043 sun.tools.jps.Jps -Denv.class.path=.:/usr/local/java/jdk1.8.0_251/lib:/usr/local/java/jdk1.8.0_251/jre/lib -Dapplication.home=/usr/local/java/jdk1.8.0_251 -Xms8m
90267 sun.tools.jstat.Jstat -Denv.class.path=.:/usr/local/java/jdk1.8.0_251/lib:/usr/local/java/jdk1.8.0_251/jre/lib -Dapplication.home=/usr/local/java/jdk1.8.0_251 -Xms8m

Display the full package name or JAR file name of the main class, and display the arguments passed to the main() method:

# jps -lm
15729 one-more-1.0.0.RELEASE.jar
59014 sun.tools.jps.Jps -lm
90267 sun.tools.jstat.Jstat -gc 15729 1000

end

Although the jps command has been around for a long time and is frequently used, it is still an "Experimental and Unsupported" tool, which may be fixed in the future, or may be silent in a certain JDK version disappeared without a trace. So, use it and cherish it.

Finally, thank you for being so handsome, and for giving me likes and attention .

{{o.name}}
{{m.name}}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324147650&siteId=291194637