How to check if a specific Java program is running with Windows CMD?

10,805

Solution 1

As noted here https://superuser.com/questions/415360/how-do-i-find-out-command-line-arguments-of-a-running-program

You can do it without Process Explorer, too, using Windows' WMI service. Run the following from the command prompt:

WMIC path win32_process get Caption,Processid,Commandline

If you want to dump the output to a file (makes it a bit easier to read), use the /OUTPUT switch:

WMIC /OUTPUT:C:\Process.txt path win32_process get Caption,Processid,Commandline

You could grep the output - if you have unix tools installed/ git-scm.

This worked too

WMIC path win32_process get Caption,Processid,Commandline | find "java"

Solution 2

You can Download Sysinternal's Process Explorer. It's a task manager much more powerfull than Windows's own manager. One of it's features is that you can see all the resources that each process is using (like registry keys, hard disk directories, named pipes, etc). So, browsing the resources that each java.exe process holds might help you determine wich one you want to kill. I usually find out by looking for the one that's using a certain log file directory.

enter image description here enter image description here

Other thing you can use the JPS utility that is included in the JRE to find the process id of a Java process. JPS tool is now included in JDK/bin directory. I also recommend to use -l option, which outputs the full package name for the application's main class, which might be helpful. The output will show you the name of the executable JAR file or the name of the main class.

Then use the Windows task manager to terminate the process. If you want to do it on the command line, use

TASKKILL /PID %PID%

Via taskkill, you can kill a process based on window title using a filter.

taskkill `/F /FI` "Your Java App Service" /T

/F - force task kill
/T - Kill child process
/FI - Filter the tasks

If the window title has quotes in it, you can escape the nested quotes with a backslash (\).

Also you can use tasklist in a similar manner to search for a task based on its window title.

tasklist /V /FI "Your Java App Service"

You can use the * as a wildcard to match a pattern

tasklist /V /FI "Your Java App S*"
Share:
10,805
LCP
Author by

LCP

Updated on August 07, 2022

Comments

  • LCP
    LCP over 1 year

    How can I find out via CMD if a certain Java program is running on my PC? When I enter

    tasklist | find "javaw"
    

    into the command line, I can see how many javaw.exe files are executed, but I can't assign which "javaw.exe" belongs to which special Java program. How do I know if my "XY.class" is currently running?

  • LCP
    LCP over 7 years
    "jps -l" shows good all running Java programs. Thank you! But what do you mean exactly with the window title?
  • Freeman
    Freeman over 7 years
    @LCP, for example when you open the app in java like swing app you can see the title of that app and recognize that from the window title, like notepad for example but it's just in wondows
  • jumping_monkey
    jumping_monkey over 4 years
    jps is a good process status command for java. You can even specify the hostid, the synopsis being jps [ options ] [ hostid ]. If jps is run without specifying a hostid, it will look for instrumented JVMs on the local host. Thank you @Freeman