Thursday, October 06, 2011

Equivalent of ps -ef | grep java in Windows

If you want to list a process and its command line, process id in Windows, this is the command:

 wmic process where "name='java.exe'" get ProcessID, Commandline /format:list

That is the equivalent of "ps -ef | grep java" in Linux. Then you could use taskkill /f /pid <PID> to kill it.


Olivier said...

Jps -l works too, it's available in the JDK (and maybe even in the JRE)

hhuynh said...

nice tip :) Thank you!

However, it has a drawback of not being able to list JDK 1.5 process info if you use jps from a JDK1.6 (only pid is shown, not command line)

USB 3G said...

Oh nice, thanks for share!

USB 3G said...

Wow… This is great! I can say that this is the first time I visited the site and I found out that this blog is interesting to read. Thanks for this awesome monitor.

Steven said...

"tasklist" also works

hhuynh said...

tasklist doesn't give you a detailed command like the above method. It doesn't show you java classpath nor java system properties, all part of the command. 

hhuynh said...

 the amount of info you get from tasklist is very minimal

$ tasklist /v | grep java                          

java.exe                     41524 Console                    1   
140,324 K Unknown        
tabby\hhuynh                                            0:00:09 N/A    

The pid.rb script wraps the wmic command in the post

$ ruby pid.rb

41524 C:\jdk\jdk1.6.0_29\bin\java.exe -Xmx512m -XX:MaxPermSize=128m

org.codehaus.plexus.classworlds.launcher.Launcher install -DskipTests

JJinTX said...

THANK YOU!!!! I really hate Windows but alas have to build stuff for the platform - this is great

Steven Penny said...

I do this with Cygwin
ps -W | grep java | cut -c-9 | xargs env kill -f