This fuser 8080/tcp will print the PID of the process bound to that port.

And this fuser -k 8080/tcp will kill that process.

Works on Linux only. More universal is use of lsof -i4 (or 6 for IPv6).

General form:

# list the TCP process bound to port PORT
fuser PORT/tcp
# Example: list the TCP process bound to port 8080
fuser 8080/tcp

# list the UDP process bound to port PORT
fuser PORT/udp
# Example: list the UDP process bound to port 8080
fuser 8080/udp
Answer from nudzo on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ linux-unix โ€บ how-to-kill-a-process-running-on-particular-port-in-linux
How to Kill a Process Running on Particular Port in Linux? - GeeksforGeeks
July 23, 2025 - For more details read this article How to Kill a Process in Linux ... kill <PID> # This method allows the process to shut down properly, saving any necessary data before exiting. The fuser command is a quick and efficient way to find and terminate ...
Discussions

How to kill a process on a port on Ubuntu - Stack Overflow
I am trying to kill a process in the command line for a specific port in Ubuntu. If I run this command, I get the port: sudo lsof -t -i:9001 so...now I want to run: sudo kill 'sudo lsof -t -i:9001... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Killport - A Simple Script to Kill Processes on a Port
I wrote this up and got distracted for the last few hours... I really, really like the simplicity! At the risk of ruining that, however, I wonder if it may be useful/wise to have a confirmation option like rm's -i? You may also like to check whether the user has the ability to kill the target proc and if not, look at launching sudo. Or just outright restrict it to root/sudo only. #!/bin/bash set -euo pipefail It's been a while since I've had to say this: Standard Warning about The Unofficial Strict Mode. readonly os=$(uname) https://www.shellcheck.net/wiki/SC2155 You may also like to look at $OSTYPE kill_port() { local port=$1 https://www.shellcheck.net/wiki/SC2155 ... probably.... You may like to consider something like port="${1:?No port defined}" to have a degree of auto-failure. It's not strictly necessary in this case, but a good habit to get into nonetheless. # Validate the port number if ! [[ "$port" =~ ^[0-9]{1,5}$ && "$port" -ge 0 && "$port" -le 65535 ]]; then echo "Invalid port number" exit 1 fi There's a bit going on here. Firstly, I would split this out into separate checks like this: printf -- '%d' "${port}" >/dev/null 2>&1 || { printf -- '%s\n' "Given port is not an integer" >&2 exit 1 } (( port > 0 && port <= 65535 )) || { printf -- '%s\n' "Given port must be between 1 and 65535" >&2 exit 1 } If the script got much bigger, you'd want to implement a die() function, so those would look more like printf -- '%d' "${port}" >/dev/null 2>&1 || die "Given port is not an integer" (( port > 0 && port <= 65535 )) || die "Given port must be between 1 and 65535" Note that I use printf. echo is a portability mess and POSIX specifies that you should use printf for that reason - they decided that echo was unfixable. Fun fact: echo in Apple's default bash is different from echo in the same version of bash on Linux. When you use echo, what you're doing is inflicting unpredictable behaviour on consumers of your code. Note also that these are error messages, so we send them to stderr. # Check if port is in use if ! type lsof >/dev/null 2>&1 || ! lsof -Pi :"$port" -sTCP:LISTEN -t >/dev/null; then echo "Port $port is not in use" exit 1 fi The more common way to check if a command exists is command -v rather than type/which/hash/-x # Kill the process if [ "$os" == "Darwin" ]; then # macOS lsof -ti tcp:"$port" | xargs kill else # Linux fuser -k "$port"/tcp fi == is best reserved for arithmetic contexts IMHO, and within single square brackets it's not a specified behaviour. Use = for string comparisons in [[]] and == for arithmetic comparisons in (()). Generally speaking. Consider a case statement instead. You can see examples of $OSTYPE in a case statement here Linux often has lsof too, you may also like to look at netstat and/or ss echo "Process on port $port killed" } # Check if port is provided if [ $# -ne 1 ]; then echo "usage: killport " exit 1 fi I would put this right towards the top of the script. You want a script to fail fast, fail early: so fail out before declaring any vars, functions etc. kill_port "$1" exit 0 Nice. More on reddit.com
๐ŸŒ r/bash
11
28
February 16, 2023
How to find and kill a Process Listening on a port in Linux? netstat and lsof command examples
UNIX isn't Linux, and (most) Linux isn't UNIX. And even on Linux, netstat (highly deprecated) and lsof may not be installed. For Linux, ss has superseded netstat, so ss may be used. On Linux, if fuser is present, that may also be used, e.g.: # fuser -n tcp 22 More on reddit.com
๐ŸŒ r/unix
2
14
October 16, 2024
ubuntu - How can I kill a process running on a specific IP and port? - Unix & Linux Stack Exchange
I was wondering, is there any way to kill a process that is running on a specific IP and port on Ubuntu 14.04 on a local IP and port? Preferably, this would be in one command, but if not, a bash sc... More on unix.stackexchange.com
๐ŸŒ unix.stackexchange.com
May 17, 2017
๐ŸŒ
AccuWeb Hosting
manage.accuwebhosting.com โ€บ knowledgebase โ€บ 3347 โ€บ How-to-Kill-a-Process-Running-on-Specific-Port-in-Linux.html
How to Kill a Process Running on Specific Port in Linux? - AccuWebHosting
Once you have the PID, use the following command to terminate it: ... To kill a process using a specific port in Linux, identify its PID using the lsof command and terminate it with kill -9. This is useful for freeing up ports when a service hangs or is misconfigured.
๐ŸŒ
Medium
medium.com โ€บ @haroldfinch01 โ€บ how-to-kill-a-process-running-on-a-particular-port-in-linux-666baa0892a9
How to Kill a Process Running on a Particular Port in Linux | by Harold Finch | Medium
May 29, 2025 - #!/bin/bash PORT=$1 PID=$(lsof -t -i:$PORT) if [ -n "$PID" ]; then echo "Killing process on port $PORT (PID $PID)" kill -9 $PID else echo "No process is using port $PORT" fi ... For long-running services, consider configuring systemd to manage ports.
Find elsewhere
๐ŸŒ
Reddit
reddit.com โ€บ r/bash โ€บ killport - a simple script to kill processes on a port
r/bash on Reddit: Killport - A Simple Script to Kill Processes on a Port
February 16, 2023 -

Have you ever encountered the issue of not being able to start a process because the port is already in use? Killport is a simple script that allows you to quickly kill any process running on a specified port.

Using Killport is easy. Simply provide the port number as a command-line argument and the script will automatically find and kill any process running on that port. The script works on both macOS and Linux, and it is easy to install.

killport

Give it a try and let me know what you think.

give a โœจ star, if you liked it. Github

Top answer
1 of 5
3
I wrote this up and got distracted for the last few hours... I really, really like the simplicity! At the risk of ruining that, however, I wonder if it may be useful/wise to have a confirmation option like rm's -i? You may also like to check whether the user has the ability to kill the target proc and if not, look at launching sudo. Or just outright restrict it to root/sudo only. #!/bin/bash set -euo pipefail It's been a while since I've had to say this: Standard Warning about The Unofficial Strict Mode. readonly os=$(uname) https://www.shellcheck.net/wiki/SC2155 You may also like to look at $OSTYPE kill_port() { local port=$1 https://www.shellcheck.net/wiki/SC2155 ... probably.... You may like to consider something like port="${1:?No port defined}" to have a degree of auto-failure. It's not strictly necessary in this case, but a good habit to get into nonetheless. # Validate the port number if ! [[ "$port" =~ ^[0-9]{1,5}$ && "$port" -ge 0 && "$port" -le 65535 ]]; then echo "Invalid port number" exit 1 fi There's a bit going on here. Firstly, I would split this out into separate checks like this: printf -- '%d' "${port}" >/dev/null 2>&1 || { printf -- '%s\n' "Given port is not an integer" >&2 exit 1 } (( port > 0 && port <= 65535 )) || { printf -- '%s\n' "Given port must be between 1 and 65535" >&2 exit 1 } If the script got much bigger, you'd want to implement a die() function, so those would look more like printf -- '%d' "${port}" >/dev/null 2>&1 || die "Given port is not an integer" (( port > 0 && port <= 65535 )) || die "Given port must be between 1 and 65535" Note that I use printf. echo is a portability mess and POSIX specifies that you should use printf for that reason - they decided that echo was unfixable. Fun fact: echo in Apple's default bash is different from echo in the same version of bash on Linux. When you use echo, what you're doing is inflicting unpredictable behaviour on consumers of your code. Note also that these are error messages, so we send them to stderr. # Check if port is in use if ! type lsof >/dev/null 2>&1 || ! lsof -Pi :"$port" -sTCP:LISTEN -t >/dev/null; then echo "Port $port is not in use" exit 1 fi The more common way to check if a command exists is command -v rather than type/which/hash/-x # Kill the process if [ "$os" == "Darwin" ]; then # macOS lsof -ti tcp:"$port" | xargs kill else # Linux fuser -k "$port"/tcp fi == is best reserved for arithmetic contexts IMHO, and within single square brackets it's not a specified behaviour. Use = for string comparisons in [[]] and == for arithmetic comparisons in (()). Generally speaking. Consider a case statement instead. You can see examples of $OSTYPE in a case statement here Linux often has lsof too, you may also like to look at netstat and/or ss echo "Process on port $port killed" } # Check if port is provided if [ $# -ne 1 ]; then echo "usage: killport " exit 1 fi I would put this right towards the top of the script. You want a script to fail fast, fail early: so fail out before declaring any vars, functions etc. kill_port "$1" exit 0 Nice.
2 of 5
3
Now try killing nfs/portmapper or wireguard :D Hint: You can't. Reason: When the kernel opens the socket there will be no pid attached to that process and you will have no way to kill it because of that. You can try that by configuring a wireguard interface. You will see that neither netstat/ss/lsof or /proc/*/fd/ be able to find that inode or pid.
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ scripting โ€บ kill a process running on a specific port in linux
Kill a Process Running on a Specific Port in Linux | Baeldung on Linux
March 18, 2024 - ... Here, the notation 9999/tcp is a shortcut for -n tcp 9999. When using fuser, we cannot query processes using protocols other than TCP or UDP. The kill command is a common command used to terminate processes.
๐ŸŒ
DEV Community
dev.to โ€บ osalumense โ€บ how-to-kill-a-process-occupying-a-port-on-windows-macos-and-linux-gj8
How to Kill a Process Occupying a Port on Windows, macOS, and Linux - DEV Community
September 19, 2024 - Here, 1234 is the PID of the process using port 5672. Killing the Process To kill the process, use the taskkill command with the PID obtained above. ... Replace 1234 with the actual PID.
๐ŸŒ
DevGenius
blog.devgenius.io โ€บ how-to-kill-a-process-running-on-a-particular-port-on-localhost-in-linux-mac-81e946eeffef
How to kill a process running on a particular port on localhost in Linux/mac? | by Ayush Tibra | Dev Genius
July 5, 2022 - If your system has npx(node package ... running port. ... This will stop/kill a process running on a specific port, replace 8080 with your port number....
๐ŸŒ
Stack Abuse
stackabuse.com โ€บ bytes โ€บ how-to-kill-a-process-using-a-port-in-linux
How to Kill a Process Using a Port in Linux
June 14, 2023 - Killing a process using a port in Linux involves finding the PID of the process using the lsof command, and then using the kill or killall command to terminate the process. This can be a useful tool for freeing up resources and troubleshooting unresponsive processes.
๐ŸŒ
Reddit
reddit.com โ€บ r/unix โ€บ how to find and kill a process listening on a port in linux? netstat and lsof command examples
r/unix on Reddit: How to find and kill a Process Listening on a port in Linux? netstat and lsof command examples
October 16, 2024 - And even on Linux, netstat (highly deprecated) and lsof may not be installed. For Linux, ss has superseded netstat, so ss may be used. On Linux, if fuser is present, that may also be used, e.g.: # fuser -n tcp 22 ... Kill a process running on a specific port.
๐ŸŒ
Linux Handbook
linuxhandbook.com โ€บ kill-process-port
Kill Process Running on a Specific Port in Linux
June 27, 2025 - You can terminate a process based on the port number it is using. Let me show you how to do that. The fuser command combined with the -k (kill) option will end all associated processes that are listening on a TCP or UDP port.
๐ŸŒ
LinuxConfig
linuxconfig.org โ€บ home โ€บ how to kill process based on the port number in linux
How to kill process based on the port number in Linux
August 22, 2022 - In order to kill a process based on its port number, we will need to use the fuser command, or use other command line tools in conjunction with the usual kill command. In this tutorial, we will show you multiple ways to kill a process based ...
๐ŸŒ
LinuxConfig
linuxconfig.org โ€บ home โ€บ how to kill process by port
Kill Process by Port Number on Linux
May 30, 2023 - Learn how to kill a process by port number on Linux using commands like fuser, lsof, and ss. Ensure process termination effectively!
๐ŸŒ
TecAdmin
tecadmin.net โ€บ kill-process-on-specific-port
How to Kill a Process Running on Specific Port
April 26, 2025 - This command first uses lsof to find the process ID (PID) of the process using port 8080, and then it immediately uses kill to stop that process. This makes it easier and quicker to manage processes on your Linux system.