How do i terminate a process tree from Java?

前端 未结 5 1232
离开以前
离开以前 2021-02-05 15:26

i am using Runtime.getRuntime().exec() command in Java to start a batch file which in turn starts another process for windows platform.

javaw.exe(Process1)
 |___         


        
5条回答
  •  情话喂你
    2021-02-05 16:06

    An alternative solution, if you control the child process as well as the batch file, would be to have the child process create a thread, open a ServerSocket, listen for a connection to it, and call System.exit() if it receives a correct password on it.

    There may be complications if you need multiple simultaneous instances; at that point you would need some way of allocating port numbers to them.

提交回复
热议问题