1.java程序启动时,把pid信息写出到文件:

1     public static long getPID() {
2         String processName =
3           java.lang.management.ManagementFactory.getRuntimeMXBean().getName();
4         return Long.parseLong(processName.split("@")[0]);
5     }

2.cmd命令行脚本,读取pid,关闭程序

 1 echo off
 2 
 3 if exist "%cd%\pid" goto read_pid
 4 goto start_run
 5 
 6 :read_pid
 7 for /f  %%i in (pid) do (
 8 set pid=%%i
 9 )
10 
11 if defined pid (taskkill /f /t /pid %pid%) else (echo server is cloased)
12 
13 echo on
14 
15 :start_run
16 call run.bat

 

相关文章:

  • 2021-06-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-30
  • 2021-12-02
  • 2021-10-04
  • 2022-01-22
猜你喜欢
  • 2021-05-31
  • 2022-12-23
  • 2021-08-02
  • 2021-12-11
  • 2022-01-05
  • 2022-12-23
  • 2022-01-09
相关资源
相似解决方案