How to find ports opened by process ID in Linux?
In Linux systems, finding ports opened by a specific Process ID (PID) can be accomplished through various methods. Below, I will introduce some commonly used approaches:Method 1: Using the Commandis a powerful networking tool that provides detailed information about network-related statistics, including the ports used by each process in the system. To identify ports opened by a specific process ID, use the following command:Here, the option specifies listening ports, indicates TCP ports, displays addresses and port numbers in numeric format, and shows the process ID and name associated with each connection or listening port. The command filters lines containing the specified process ID.For example, to find ports opened by process ID 1234, execute:Method 2: Using the CommandThe command is a modern alternative to for viewing socket information. Similar to , it can be used to locate ports opened by specific processes:The options are consistent with : specifies listening ports, indicates TCP, displays numeric format, and shows process details. The command filters lines containing the specified process ID.For instance, to find ports opened by process ID 1234, use:Method 3: Directly Viewing the File SystemThe Linux file system contains runtime system information, including details about each process. Each process has a directory named after its PID (e.g., ), which includes a subdirectory listing all file descriptors opened by the process, including network sockets.To inspect ports for a specific PID, run:Then, examine the symbolic links to identify file descriptors of type socket.ExampleFor example, to check the port usage of process ID 1234, combine and :This command displays all socket-related file descriptors opened by the process.The above methods provide several approaches to find ports opened by a specific process ID in Linux. Each method has its own use cases, and you can select the most suitable one based on your requirements.