网上看了一圈,不少修改java二进制文件的,那也太麻烦了
去Google搜索,关键词how to identify java process all named java
看到了StackOverflow的页面
StackOverflow – How to find the process id of a running Java process on Windows? And how to kill the process alone?
支持数最高的回答,清晰、简单明了
You can use the jps utility that is included in the JDK to find the process id of a Java process. The output will show you the name of the executable JAR file or the name of the main class.
你可以使用JDK提供的名为jps
的工具来查看Java进程的进程ID,终端输出内容将会向你展示 可执行JAR文件 或是 主类 的名称
那就好办了
执行jps二进制文件就好了,如果添加了环境变量则直接运行jps
命令,如果没有,通过路径执行
(本人环境为macOS12, OpenJDK17)
示例:
$ jps
84403
31510 Launcher
31511 MyJavaApplication
31672 Jps
第一个字段为PID
以下为个人观察,当放屁就好:
当使用IDEA运行Java应用时
空名称进程为IDEA
而Jps进程会在打印信息后立即终止
Launcher进程则会在每次运行IDEA Java应用时启动,当Java程序停止时,Launcher进程依然不会终止
使用--help
参数或者man手册以查看更多使用方法