Current location - Quotes Website - Collection of slogans - How to get port number by process ID under Linux
How to get port number by process ID under Linux
The basic logic is,

1)ls-l/proc/& lt; pid & gt/fd

[~]$ ll /proc/ 12753/fd

LRWX-. 1xxxx64 March 8th18: 50 3->; Socket: [84 1683]

2) filter /proc/net/tcp using the above socket-inode.

[~]$ cat/proc/net/TCP | grep 84 1683

# sl local _ address rem _ address ST tx _ queue rx _ queue tr TM-& gt; When returned, the uid timed out the inode.

7:xxxxa 8 c 0:8 a92 xxxxa 8 c 0:00 16 0 1 00000000000 02:000 a 6 136 000000000 523 0 84 1683 2 ffff 880034936 a80 2 1 3 14 65448

3) Obtain the source address-> Destination address (hexadecimal to decimal)

192. 168 . x . x:35474->; 192. 168.x.x:22