Oneliner command to use kill given tcp port number instead of PID?

Niklas R.

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?

Florian Diesch

fuser can do that:

sudo fuser -KILL -k -n tcp 8088

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Why UDP and TCP use port number but not PID to locate the destination?

linux + port in use + but no PID return from netstat to kill the PID

Port In Use code: 'EADDRINUSE', even after kill command

How to kill a process in Java, given a specific PID

Kill multiple processes by name instead of pid

Windows Kill Process By PORT Number

return the pid of the command instead returning tee pid

Oneliner to get the command which started a process on a certain port

Port TCP is always in use

How to combine "lsof -i :port" and "kill pid" in bash

linux command to kill a process in a running port

One command to kill a process using a specific port

Kill a java process (in linux) by process name instead of PID

How to kill the process using the name of the program instead of PID?

How can I kill a process by name instead of PID?

how to Find the port number according to PID

Port 8000, PID 4, not able to kill, taskill /f /pid 4, Access Denied

Continuously check if tcp port is in use

How to kill a process by port on MacOS, a la fuser -k 9000/tcp

How can I kill TCP port 16969 in Bash?

How to create alias to kill processes running on a TCP/IP port?

Linux: How to kill programs that use port 1935?

Linux: How to kill programs that use port 1935?

Beego - Make use of port number from docker-compose implementaion instead using port number from app.conf

Different ways to use /dev/tcp/host/port command and where to find manual pages on this

What TCP port number does the aws cli s3 use?

Is there any reason to use 'kill' instead of 'killall'/'pkill'?

Maximum tcp port number constant in java

how to use a docker container kill [containerID] command to kill a container