Search code examples
javacommand-linepid

Java - get PID of external process by command line in Windows 7


I have Windows 7 32 bit with Java:

How do I get the PID of a process by command line in Windows 7?

I want to kill an application which I only can truly identify by the command line which ran it. We have several Java applications running on that machine. I need to stop specific ones.

To be exact: I need to find tomcat which is run by catalina.bat. What do you think is the best way to do this?

I know of tasklist, but it does not seem to be able to query the command line which started the process. Finding java.exe does not help me. I tried searching for something useful like pgrep/pkill for Windows, with no success.


Solution

  • Finally found something. The solution working for me is called wmic (Windows Management Instrumentation Commandline). This nice tool comes built-in to Windows 7 Pro (mine) and possibly other Windows versions. It provides a quite large variety of actions like listing all the running tasks with every details you can imagine (like their corresponding command line), various hardware info, etc. Exactly what I need.