开发者

Get the name of the java process instead of pid?

jps.exe which found on JDK 1.5 and later could monitor all Java process but is there a way to detect开发者_开发知识库 the specify command line and terminate the correct pid?

What if the user have JRE, is there a similar code allow us to terminate any process easily?

Prefer to keep the topic on Windows which I am working on.


The jps command supports a number of options that modify the output of the command. These options are subject to change or removal in the future.

-q Suppress the output of the class name, JAR file name, and arguments passed to the main method, producing only a list of local VM identifiers.

-m Output the arguments passed to the main method. The output may be null for embedded JVMs.

-l Output the full package name for the application's main class or the full path name to the application's JAR file.

-v Output the arguments passed to the JVM.

-V Output the arguments passed to the JVM through the flags file (the .hotspotrc file or the file specified by the -XX:Flags= argument).

Pipe the output of jps to grep or sed or awk or perl or even another Java program for further matching, parsing and action. On Windows, the easiest way to get those utilities is through Cygwin.

Here are some Microsoft downloadable command line utilities which are useful for working with processes on Windows:

  • pskill
  • pslist
  • and the rest of the Sysinternals Suite


If the user don't have jps, you can use ps. The command line options for ps differs between platforms, see man ps on you system. I use ps -C java -o pid,time,cmd to list java processes on a CentOS system. Then kill to terminate.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜