Freeing Up a Stuck Port in Linux Using SS and Kill
Jeremy Barber
·6/8/2025
Step 1: Find the Process Using the Port
Use the ss (socket statistics) command to list all processes listening on a specific port:
ss -tulnp | grep 8080
-t: TCP
-u: UDP
-l: Listening sockets
-n: Show numerical addresses
-p: Show process using the socket
You’ll get output similar to:
tcp LISTEN 0 511 *:8080 *:* users:(("MainThread",pid=237743,fd=21))
Step 2: Extract the PID
To isolate the PID from that line:
ss -tulnp | grep 8080 | awk '{print $NF}' | cut -d ',' -f 2 | cut -d '=' -f 2
This command chain:
Extracts the last field using awk
Splits by comma and selects the PID field
Splits by = to get the actual PID
Example output:
237743
Step 3: Kill the Process
Once you have the PID, terminate it:
kill -9 237743
Or automate the whole process in one line:
kill -9 $(ss -tulnp | grep 8080 | awk '{print $NF}' | cut -d ',' -f 2 | cut -d '=' -f 2)
This forcefully kills the process holding onto port 8080.
Summary
When a port is stuck:
Use ss -tulnp to identify the process.
Extract the PID.
Kill the process using kill -9