Suppose the PID of the process is already known
相关问题
- Is shmid returned by shmget() unique across proces
- IPAddress.[Try]Parse parses 192.168 to 192.0.0.168
- how to get running process information in java?
- JQ: Select when attribute value exists in a bash a
- Error building gcc 4.8.3 from source: libstdc++.so
You can use the command below:
As a side note, netstat -ao will read the /proc/PID/tcp etc to see the ports opened by the process. This means that its reading information supplied by the system (the linux KERNEL), and is in no way directly looking on the network interface or other means. Same goes for lsof.
If you are doing this as a security measure, you failed. You should never (NEVER EVER) trust the output of netstat, even if you are 100% sure you are in fact running a real netstat program (as opposed to a trojaned version) or any other program that reads the /proc filesystem. Some people seem to think that netstat, ls, ps or any other of the standard unix tools do some sort of magic and poll information from the sources, the truth is all of them rely on the /proc filesystem to get all of their data, which can be easily subverted by a rootkit or hypervisor.
In some embedded devices or with old version of Linux, the problem is
netstat
do not have--process
or-p
options available.The following script shows process with its IP and port, you must be root.
The output is like:
You can use the netstat command line tool with the
-p
command line argument:The example section gives this example:
With ls you can know the process route.
Example:
The fuser command says that the process is: 2054
The process path appears
Extracted from: https://www.sysadmit.com/2018/06/linux-que-proceso-usa-un-puerto.html
Image example
--all
show listening and non-listening sockets.--program
show the PID and name of the program to which socket belongs.You could also use a port scanner such as Nmap.