Home > Back-end >  Kill process that is running on certain port in java
Kill process that is running on certain port in java

Time:08-16

Is it possible to kill a process using port that it is listening on in java?
I know on linux you can use fuser command but I would prefer to do it programatically and make it OS universal.

CodePudding user response:

Call netstat -p. Netstat will print the pid if you have sufficient privileges. Next call kill to terminate the process.

You can do that manually, you can as well script it or code it in Java.

CodePudding user response:

I have decided to use KISS rule and just timeout process my program starts instead of performing dangerous OS commands

  • Related