How To Check Process Running On Port In Linux

To check which process is running on a specific port in Linux, you can use the lsof (list open files) or netstat commands. Here’s how you can do it:

Using lsof command:

  • Open a terminal.
  • Run the following command, replacing <port_number> with the port number you want to check:
  • sudo lsof -i :<port_number>
  • This command will list the processes that have open connections on the specified port.
sudo lsof -i 8080

Using netstat command:

  1. Open a terminal.
  2. Run the following command to list all listening sockets and their associated processes:
  3. sudo netstat -tuln | grep <port_number>
  4. Replace <port_number> with the port number you want to check. The -t option filters for TCP connections, the -u option filters for UDP connections, the -l option shows only listening sockets, and the -n option displays numeric addresses and port numbers.The output will display the process ID (PID) and the process name or command associated with the specified port.
sudo netstat -tuln | grep 8080

Please note that both commands may require administrative privileges (sudo) to display all processes and their associated ports. Additionally, if the lsof command is not installed on your system, you can install it using the package manager specific to your distribution (e.g., apt for Debian/Ubuntu, dnf for Fedora/CentOS).