List of Java processes

360,783

Solution 1

try:

ps aux | grep java

and see how you get on

Solution 2

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,

[nsushkin@fulton support]$ jps -m
2120 Main --userdir /home/nsushkin/.netbeans/7.0 --branding nb
26546 charles.jar
17600 Jps -m

Solution 3

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

Solution 4

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

Solution 5

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

pgrep -fl java
Share:
360,783
Jacek Koralik
Author by

Jacek Koralik

Updated on February 28, 2021

Comments

  • Jacek Koralik
    Jacek Koralik about 3 years

    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.

  • jake
    jake almost 9 years
    Just a note: jps only ships with the JDK, not the JRE. Machines with plain ol' Java runtimes on them won't have this tool.
  • Sridhar Sarnobat
    Sridhar Sarnobat over 7 years
    Wow, that's even better than jps
  • vaquar khan
    vaquar khan almost 7 years
    it should be ps -eaf | grep Java not [j]ava
  • Ilya Gazman
    Ilya Gazman almost 7 years
    @vaquarkhan dude just try to run both yours and mine suggestions and see whats the difference, they both will work
  • vaquar khan
    vaquar khan almost 7 years
    Both give same results however [j]ava is confusing
  • Toby Speight
    Toby Speight almost 7 years
    Thank you for this code snippet, which may provide some immediate help. A proper explanation would greatly improve its educational value by showing why this is a good solution to the problem, and would make it more useful to future readers with similar, but not identical, questions. Please edit your answer to add explanation, and give an indication of what limitations and assumptions apply. In particular, why doesn't the second of those show the grep process?
  • Jet
    Jet over 6 years
    how can I get just count of running java process ?
  • David Clarke
    David Clarke almost 5 years
    This is what I was looking for - $ top just gives "java" as the command which isn't all that helpful when trying to figure out which process is hogging the cpu. $ ps ww -fC java provides the missing pieces of the puzzle.
  • Charles Naccio
    Charles Naccio over 4 years
    Nice an clean output; exactly what I was looking for. Thanks!
  • Davut Gürbüz
    Davut Gürbüz over 3 years
    I've been utilizing this for years, however it only shows current user's processes. Not all processes on the machine. Admin user and normal user processes might be different.
  • Aleksandar
    Aleksandar over 2 years
    That works great in a container with limited packages. For example if ps is missing.