Using jps - Java Processes tool

JPS is a tool that lists Java processes running in the system. It is just like ps but for Java processes only.


The disadvantage with ps is that you need to explicitly do a grep for java processes, something like ps -ef | grep java. Even this command might not work all the time. Because it might list all processes that contain java in it, so you might be getting even a process running in a directory that has java as the term or its command line has java in it.


To better solve the problem, we use jps

Usage

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

Definitions:
    <hostid>:      <hostname>[:<port>]

Examples

# Brief out the java processes
$ jps
29521 org.eclipse.equinox.launcher_1.5.0.v20180512-1130.jar
12029 Jps

# List only the process ids
$ jps -q
29521
12063

# List the full command line
$ jps -m
29521 org.eclipse.equinox.launcher_1.5.0.v20180512-1130.jar -os linux -ws gtk -arch x86_64 -showsplash -launcher /home/test/mat/MemoryAnalyzer -name MemoryAnalyzer --launcher.library /home/test/mat//plugins/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.1.700.v20180518-1200/eclipse_1705.so -startup /home/test/mat//plugins/org.eclipse.equinox.launcher_1.5.0.v20180512-1130.jar --launcher.overrideVmargs -exitdata e48030 -vm /usr/bin/java -vmargs -Xmx10g -jar /home/test/mat//plugins/org.eclipse.equinox.launcher_1.5.0.v20180512-1130.jar
12138 Jps -m

# Get the pid of specific process
$ jps -m | grep eclipse | cut -d ' ' -f 1
29521
# Same as above (without cmd line)
$ jps | grep eclipse | cut -d ' ' -f 1
29521

# List the full path
$ jps -l
29521 /home/test/mat//plugins/org.eclipse.equinox.launcher_1.5.0.v20180512-1130.jar
13321 sun.tools.jps.Jps

# List the system properties
$ jps -v
29521 org.eclipse.equinox.launcher_1.5.0.v20180512-1130.jar -Xmx10g
13535 Jps -Dapplication.home=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.181-3.b13.el6_10.x86_64 -Xms8m

# Cmdline + path + system properties
$ jps -mlv
29521 /home/test/mat//plugins/org.eclipse.equinox.launcher_1.5.0.v20180512-1130.jar -os linux -ws gtk -arch x86_64 -showsplash -launcher /home/test/mat/MemoryAnalyzer -name MemoryAnalyzer --launcher.library /home/test/mat//plugins/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.1.700.v20180518-1200/eclipse_1705.so -startup /home/test/mat//plugins/org.eclipse.equinox.launcher_1.5.0.v20180512-1130.jar --launcher.overrideVmargs -exitdata e48030 -vm /usr/bin/java -vmargs -Xmx10g -jar /home/test/mat//plugins/org.eclipse.equinox.launcher_1.5.0.v20180512-1130.jar -Xmx10g
13999 sun.tools.jps.Jps -mlv -Dapplication.home=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.181-3.b13.el6_10.x86_64 -Xms8m

ధన్యవాదాలు (Thanks)

No comments: