How to Check Which Process Is Using a Port in Linux (ss, lsof, netstat)

Problem Overview

  • When a service fails to start or a port shows as “already in use”, it usually means another process is already listening on that port.

  • To fix the issue, you first need to identify which process is using the port and stop or reconfigure it safely.

Prerequisites

Before starting, make sure the following conditions are met:

  • Terminal access with sudo privileges

  • Basic understanding of services and processes

Solution

  • Check port usage with ss (socket statistics), It is the preferred tool on modern Linux systems and replaces netstat.
    • [root@pythonlinuxhub ~]# sudo ss -tulpn | grep :80
      tcp   LISTEN 0      511                                    *:80              *:*    users:(("httpd",pid=2899,fd=4),("httpd",pid=2898,fd=4),("httpd",pid=2897,fd=4),("httpd",pid=2892,fd=4))
  • Check using lsof, It lists open files, and in Linux, ports are treated as files.
    • [root@pythonlinuxhub ~]# sudo lsof -i :80
      COMMAND  PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
      httpd   2892   root    4u  IPv6  33917      0t0  TCP *:http (LISTEN)
      httpd   2897 apache    4u  IPv6  33917      0t0  TCP *:http (LISTEN)
      httpd   2898 apache    4u  IPv6  33917      0t0  TCP *:http (LISTEN)
      httpd   2899 apache    4u  IPv6  33917      0t0  TCP *:http (LISTEN)
    • This method is very useful when you need user ownership and detailed process info.

  • Check using netstat, It is deprecated but still available on older Linux distributions.
    • [root@pythonlinuxhub ~]# netstat -tulpn | grep :80
      tcp6       0      0 :::80                   :::*                    LISTEN      2892/httpd
    • If netstat is not installed, install it using yum install net-tools

  • Once you identify the PID, inspect it before stopping

    • ps -fp 
  • Gracefully stop the process
    • sudo kill 
  • If the process does not stop
    • sudo kill -9 
  • Some ports are opened by services controlled by systemctl.

    • Identify the service
      • sudo systemctl status 
    • Stop the service safely
      • sudo systemctl stop 
    • Prevent if from starting on boot
      • sudo systemctl disable 

Note:

  • Do not kill system-critical services blindly. Always verify what the process is and whether it’s managed by systemd.

Shaik Mohammed Faruk

Software Engineer sharing practical tutorials and insights on Linux, Python, SQL, and modern technologies.

Read more About Me

0 0 votes
Article Rating
guest

3 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
vipph1
1 day ago

VIPPH1 is similar enough in what the other one does. I would check this out too if you want. Checkout vipph1

jilibetapk
1 day ago

Need to download the jilibetapk, is it safe? Does it work well on Android? I want a smooth experience. Learn more jilibetapk.

phspinapp
1 day ago

Phspinapp good app to play, need to try! Free spins and good payout right? Wanna know more about how to play. Checkout phspinapp.

Thanks for your interest!

Content for this is getting ready and will be published soon.

3
0
Would love your thoughts, please comment.x
()
x