Finding process using ports

To find out which process is using port number 35541 in a CentOS 7 system (or any Linux distribution), you can use the following methods:

1. Using lsof (List Open Files)

The lsof command can list all open files and network connections, and you can filter by the specific port:

bash 复制代码
sudo lsof -i :35541

This will show the process that is using port 35541. The output will contain columns for the command, PID (process ID), and other information.

2. Using netstat

If netstat is installed, you can use it to check for connections on a specific port:

bash 复制代码
sudo netstat -tuln | grep 35541

This will show which process is listening on that port. If you need the process ID (PID), use the following command:

bash 复制代码
sudo netstat -tulnp | grep 35541

3. Using ss (Socket Statistics)

The ss command is often recommended as a modern replacement for netstat:

bash 复制代码
sudo ss -tuln | grep 35541

To include the process ID:

bash 复制代码
sudo ss -tulnp | grep 35541

4. Using fuser

You can also use fuser, which shows which processes are using files or sockets:

bash 复制代码
sudo fuser 35541/tcp

35541/tcp: 30408

Using fuser to identify the process occupying the port and then restarting it is an effective approach to address such conflicts.

This will return the process ID (PID) that is using the port.

Once you get the PID, you can get more information about the process by running:

bash 复制代码
ps -p <PID>

Replace <PID> with the actual process ID obtained from one of the above methods.

If netstat didn't show the process as listening on port 35541, then it's likely that the port was being used by a client connection rather than a server process.

In TCP/IP networking, a process can bind to a local ephemeral port when making outbound connections as a client. The fact that port 35541 was in use by process 30408 suggests that it was likely a client-side connection, where the process was using 35541 as the source port for an outbound connection.

Here's a more detailed breakdown:

  • Listening port (server) : The process listens on a specific port, usually waiting for incoming connections. This would show up in netstat as LISTEN if it were a server process.
  • Client-side port : When a process initiates an outgoing TCP connection, the operating system assigns a source port , often from a range of ephemeral ports. These ports are usually dynamically assigned and temporary. The port 35541 was likely used in this capacity by process 30408.

To confirm this hypothesis:

  1. You could check all active connections, not just listening ones:

    bash 复制代码
    sudo netstat -anp | grep 30408

    This would show any connections (both listening and established) made by the process with PID 30408.

  2. Similarly, using ss to list all connections for this process:

    bash 复制代码
    sudo ss -ap | grep 30408

    This should show both inbound and outbound connections, confirming the client-side use of port 35541.

By restarting the process, the client-side connection was reset, likely freeing up the port.

相关推荐
AGI学习社11 分钟前
2024中国排名前十AI大模型进展、应用案例与发展趋势
linux·服务器·人工智能·华为·llama
H.2032 分钟前
centos7执行yum操作时报错Could not retrieve mirrorlist http://mirrorlist.centos.org解决
linux·centos
9毫米的幻想1 小时前
【Linux系统】—— 编译器 gcc/g++ 的使用
linux·运维·服务器·c语言·c++
helloliyh1 小时前
Windows和Linux系统安装东方通
linux·运维·windows
van叶~3 小时前
Linux探秘坊-------4.进度条小程序
linux·运维·小程序
秋风&萧瑟3 小时前
【数据结构】顺序队列与链式队列
linux·数据结构·windows
我科绝伦(Huanhuan Zhou)3 小时前
Linux 系统服务开机自启动指导手册
java·linux·服务器
hunter2062065 小时前
ubuntu终端当一段时间内没有程序运行时,自动关闭终端。
linux·chrome·ubuntu
代码讲故事7 小时前
从Windows通过XRDP远程访问和控制银河麒麟ukey v10服务器,以及多次连接后黑屏的问题
linux·运维·服务器·windows·远程连接·远程桌面·xrdp
qq_243050799 小时前
irpas:互联网路由协议攻击套件!全参数详细教程!Kali Linux入门教程!黑客渗透测试!
linux·网络·web安全·网络安全·黑客·渗透测试·系统安全