Java Process List

How can I list all Java processes in bash? I need a command line. I know there is a ps command, but I do not know what parameters I need to use.

+74
command-line linux unix bash
Jun 08 '11 at 18:00
source share
16 answers

to try:

 ps aux | grep java 

and see how you get on

+91
Jun 08 2018-11-18T00:
source share
โ€” -

Recent Java version equipped with jps tool for Java virtual machine processing

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 
+82
Jun 08 2018-11-11T00:
source share
 jps -lV 

is most useful. Prints only the pid and qualified name of the main class:

 2472 com.intellij.idea.Main 11111 sun.tools.jps.Jps 9030 play.server.Server 2752 org.jetbrains.idea.maven.server.RemoteMavenServer 
+30
Jun 09 '15 at 16:16
source share

You can use a single pgrep command (does not require the use of pipes and several commands):

 pgrep -fl java 
+23
Jun 08 '11 at 18:22
source share

Starting with Java 7 , the easiest way and less error prone is to simply use the jcmd command , which is part of the JDK , to work the same on all OSs.

Example:

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

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

Learn more about how to use jcmd .

See also jcmd Utility

+14
May 11 '16 at 16:37
source share

This will return all running java processes in the linux environment. Then you can kill the process using the process id.

 ps -e|grep java 
+10
Feb 23 '15 at 15:25
source share

If I want to just list java processes, use:

 ps -A | grep java 
+7
04 Oct '13 at 12:04 on
source share
 ps axuwww | grep java | grep -v grep 

The above will be

  • show you all processes with long lines (arg: www)
  • filter (grep) only lines containing the word java, and
  • filter the string "grep java" :)

(By the way, this example is not effective, but just remembered);)

you can pass the above commands to other commands, for example:

 ps axuwww | grep java | grep -v grep | sed '.....' | while read something do something_another $something done 

etc...

+3
Jun 08 '11 at 18:19
source share

When I want to find out if any Java class is running, I use the following command line:

 ps ww -f -C java | grep "fully.qualified.name.of.class" 

From an operating system point of view, the name of the process command is "java". The "ww" option extends the maximum colum characters, so you can grep the FQN of the associated class.

+2
Oct 15 '14 at 4:30
source share

To find out the java list running on a Linux machine. ps -e | grep java

+1
May 2 '15 at 8:30
source share

There are many ways to do this. You can use java.lang.ProcessBuilder and "pgrep" to get the process identifier (PID) with something like: pgrep -fl java | awk {'print $1'} pgrep -fl java | awk {'print $1'} . Or, if you are running Linux, you can request the /proc directory.

I know this seems horrible, and unbearable, and even poorly implemented, I agree. But since Java actually works in VM, for some absurd reason that I canโ€™t understand after more than 15 years of working with the JDK, why it is impossible to see things outside the JVM space, itโ€™s really funny to think about it with you. You can do the rest, even fork and join child processes (it was a terrible way to multitask when the world didn't know about threads or pthreads , what the hell was going on with Java ?! :).

This will give a huge discussion that I know, but in any case there is a very good API that I have already used in my projects, and it is quite stable (this is OSS, so you still need to emphasize each version you use before trusting the API) : https://github.com/jezhumble/javasysmon

JavaDoc: http://jezhumble.imtqy.com/javasysmon/ , find the class com.jezhumble.javasysmon.OsProcess , it will do the trick. Hope this helps, good luck.

+1
04 Sep '15 at 1:35
source share

jps and jcmd did not show me any results when I tried this using openjdk-1.8 on redhat linux. But even if this were done, it only shows processes under the current user that do not work in my case. Using ps | grep is what I ended up with, but the class path for some Java applications can be extremely long, which makes the results illegible, so I used sed to remove it. This is a little rude, but removes everything except: PID, User, java-class / jar, args.

 ps -o pid,user,cmd -C java | sed -e 's/\([0-9]\+ *[^ ]*\) *[^ ]* *\([^$]*\)/\1 \2/' -e 's/-c[^ ]* [^ ]* \|-[^ ]* //g' 

The results look something like this:

  PID USER CMD 11251 userb org.apache.zookeeper.server.quorum.QuorumPeerMain ../config/zookeeper.properties 19574 userb com.intellij.idea.Main 28807 root org.apache.nifi.bootstrap.RunNiFi run 28829 root org.apache.nifi.NiFi 

An alternative for windows to display all processes is:

 WMIC path win32_process where "Caption='java.exe'" get ProcessId,Commandline 

But this will require analysis to make it more understandable.

+1
Feb 16 '17 at 18:43
source share

I use this (good on Debian 8): alias psj='ps --no-headers -ww -C java -o pid,user,start_time,command'

0
Apr 04 '16 at 14:41
source share
 pgrep -l java ps -ef | grep java 
0
Jul 31 '17 at 19:18
source share

ps aux | grep java

or

$ ps -fea|grep -i java

0
Oct 05 '17 at 9:28
source share
  ps -eaf | grep [j]ava 

This is better since it will show you only the active processes, not including this command, which also received the java string. [] performs the trick

-one
Jun 13 '17 at 1:24 on
source share



All Articles