Grimalkin
Grimalkin

Reputation: 107

Kill process that is running on certain port in java

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.

Upvotes: 1

Views: 1181

Answers (2)

Grimalkin
Grimalkin

Reputation: 107

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

Upvotes: 1

queeg
queeg

Reputation: 9384

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.

Upvotes: 0

Related Questions