简体   繁体   English

如何检查Windows CMD是否正在运行特定的Java程序?

[英]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? 如果PC上正在运行某个Java程序,如何通过CMD进行查找? 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. 在命令行中,我可以看到执行了多少个javaw.exe文件,但是我无法指定哪个“ javaw.exe”属于哪个特殊的Java程序。 How do I know if my "XY.class" is currently running? 我怎么知道我的“ XY.class”当前正在运行?

As noted here https://superuser.com/questions/415360/how-do-i-find-out-command-line-arguments-of-a-running-program 如此处所述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. 您也可以使用Windows的WMI服务在没有Process Explorer的情况下进行操作。 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: 如果要将输出转储到文件中(使其更易于阅读),请使用/ OUTPUT开关:

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. 您可以grep输出-如果您已安装unix工具/ git-scm。

This worked too 这也起作用

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

You can Download Sysinternal's Process Explorer . 您可以下载Sysinternal的Process Explorer It's a task manager much more powerfull than Windows's own manager. 它是一个任务管理器,比Windows自己的管理器功能强大得多。 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. 因此,浏览每个java.exe进程所拥有的资源可能有助于您确定要杀死的资源。 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. 您还可以使用JRE中包含的JPS实用程序来查找Java进程的进程ID。 JPS tool is now included in JDK/bin directory. JPS工具现在包含在JDK / bin目录中。 I also recommend to use -l option, which outputs the full package name for the application's main class, which might be helpful. 我还建议使用-l选项,该选项输出应用程序主类的完整软件包名称,这可能会有所帮助。 The output will show you the name of the executable JAR file or the name of the main class. 输出将显示可执行JAR文件的名称或主类的名称。

Then use the Windows task manager to terminate the process. 然后使用Windows任务管理器终止该过程。 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,您可以使用过滤器杀死基于窗口标题的进程。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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