How to check which process is using a port in Linux?

On Linux, you can use the following command to see which process is using a particular port:

  1. Utilize the netstat command:
netstat -tlnp | grep <端口号>

The -tlnp option is used to display all listening ports for TCP and UDP, and the grep command is used to filter out lines with specific ports. In the output, you can see the relevant process ID (PID).

  1. “Using the lsof command:”
sudo lsof -i :<端口号>

The -i option is used to display network-related files, followed by the port number. You need to use the sudo command to run this command with root privileges. In the output, you can see the relevant Process ID (PID).

  1. Use the ss command:
ss -ltnp | grep <端口号>

The -ltnp option is used to display the listening ports of TCP, and the grep command is used to filter out the lines of specific ports. In the output, you can see the related Process ID (PID).

The commands above will display the corresponding process IDs (PIDs), which you can use to further search for detailed information about the process. For example, using the ps command:

ps -p <进程ID> -f

This will display detailed information about the specified process ID, including the command line parameters of the process.

bannerAds