Friday, May 3, 2024
 Popular · Latest · Hot · Upcoming
10
rated 0 times [  10] [ 0]  / answers: 1 / hits: 3357  / 1 Year ago, wed, may 24, 2023, 8:24:57

I often do e.g.



sudo netstat -lpn |grep :8088


view the output



tcp6       0      0 :::8088                 :::*                    LISTEN      11189/java


and then



sudo kill -kill 11189


I'd like to have a more convenient command exactly like killatport 8088 that uses the tcp port number as a variable and that I can make as an alias to a pipeline that does what I want, but how do I get the PID from the output and pipe it to the kill command? I suppose I might be able to use awk to get the PID from the output from netstat, but how do I safeguard and make an exact port match so that the input 80 won't match 8080 and likewise? Should I make it a C program instead? Or is there already a small utility like this?


More From » bash

 Answers
2

fuser can do that:



sudo fuser -KILL -k -n tcp 8088

[#26895] Friday, May 26, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
allally

Total Points: 487
Total Questions: 106
Total Answers: 110

Location: Laos
Member since Sun, Jul 3, 2022
2 Years ago
;