Advertisement
Advertisement


List of Java processes


Question

How can I list all Java processes in bash? I need an command line. I know there is command ps but I don't know what parameters I need to use.

2011/06/08
1
113
6/8/2011 6:00:42 PM


Recent Java comes with Java Virtual Machine Process Status Tool "jps"

http://download.oracle.com/javase/1.5.0/docs/tooldocs/share/jps.html

For example,

[[email protected] support]$ jps -m
2120 Main --userdir /home/nsushkin/.netbeans/7.0 --branding nb
26546 charles.jar
17600 Jps -m
2011/06/08

jps -lV

is most useful. Prints just pid and qualified main class name:

2472 com.intellij.idea.Main
11111 sun.tools.jps.Jps
9030 play.server.Server
2752 org.jetbrains.idea.maven.server.RemoteMavenServer
2015/06/09

You can use single command pgrep as well (doesn't require you to use pipes and multiple commands):

pgrep -fl java
2011/06/08

Starting from Java 7, the simplest way and less error prone is to simply use the command jcmd that is part of the JDK such that it will work the same way on all OS.

Example:

> jcmd
5485 sun.tools.jcmd.JCmd
2125 MyProgram

jcmd allows to send diagnostic command requests to a running Java Virtual Machine (JVM).

More details about how to use jcmd.

See also the jcmd Utility

2016/11/19

For better output format check this command:

ps -fC java
2019/02/08