简体   繁体   中英

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

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?

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"

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.

在此处输入图片说明 在此处输入图片说明

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*"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM