How to find the PID of the process running on a specific port ?
This sneppet will guide you on how to find the PID of the process running on a specific port. PID stands for Process ID. It is a unique number assigned to each process running on any machine. And this PID is used to identify and manage the processes running on a machine.
Find the PID of the process running on a specific port
lsof command
Using lsof command is the most straight-forward way and probably the simplest way to find the PID of the process using a specific port.
For example,
lsof -i :8080
The above command will directly give you the process ID (PID) and other details related to process that is listening on port specified.
netstat command
Alternatively, you can also use the following netstat command to find the PID.
For example,
netstat -tlnp | grep :8080
ss command
Using ss command is even more concise and another way to find the PID of the process using a specific port.
For example,
ss -tlnp 'sport = :8080'
The above command will give you the process ID (PID) and other process related details listening on to the specified port.
Please note, the ss command is often preferred over the netstat command as it is faster and more efficient than the netstat approach.
There are several reasons why you might want to find the PID of the process using a specific port, may be for troubleshooting purpose, to kill a process, to manage system resources such as memory and CPU usage, to investigate potential security issues such as unauthorized access, while debugging applications especially when working with networked applications etc.,
You will find the above methods useful for the cases mentioned. Please note, if the above commands does not work for you, then there might be some permission issue as sometimes Linux requires you to be either root or the owner of the process to get the required information.
The following command will show you the process details including owner information.
ls -l /proc/<PID>
Note: The /proc/<PID> directory has the information about the process with the specified process ID.
For example,
ls -l /proc/1234 dr-xr-xr-x 7 root root 0 Jan 12 14:30 .
In the above example, the owner of the process with PID 1234 is root. The first root is the owner’s username, and the second root is the group name.
Where,
dr-xr-xr-x are the permissions
7 is the number of hard links
root is the owner’s username
root is the group name
0 is the size of the directory
Jan 12 14:30 is the timestamp
- Set or change root password in Ubuntu Linux
- Linux: sudo: apt-get: command not found
- How to Start Stop Restart MariaDB on Linux OS ?
- Putty Fatal Error No supported authentication methods available
- How to find which users belongs to a specific group in linux
- Give write permissions for specific user or group for specific folder in linux
- How to unzip a zip file from Terminal (Google Cloud Shell)
- Build a Docker Image with a Dockerfile and Cloud Build in GCP?
- How to create GCP project on Google Cloud Platform
- MariaDB – How to set max_connections permanently ?
- How to check sshd logs and status in linux ?
- Create non-root SSH user account and provide access to specific folders
- MySQL : How to grant all privileges to the user on database ?
- Amazon Linux AMI : apt-get command not found
- How to get the first and last element of a list in Python ?
- Find the PID of the process that is using specific port ?
- Clear the terminal history in Linux ?
References