Introduction to finding connection status via socket file descriptor in Linux

Source: Internet
Author: User
Tags socket

The proc virtual file system has a number of named subdirectories below that represent the number of processes currently running on the system;

The open file descriptor is saved under the/PROC/N/FD directory, pointing to a link to the actual file. As follows:

The code is as follows:

[root@xxxxxxx_10_1_17_138 song_test]# LL/PROC/25465/FD

Total 0

LRWX------1 root Apr 09:36 0->/DEV/PTS/4 (deleted)

LRWX------1 root Apr 09:36 1->/dev/pts/4 (deleted)

LRWX------1 root 09:36-> socket:[2289128790]

LRWX------1 root 09:36-> socket:[2305227922]

LRWX------1 root 09:36-> socket:[2305224138]

LRWX------1 root Apr 09:36 102-> socket:[2305233625]

LRWX------1 root Apr 09:36-> socket:[2305215571]

LRWX------1 root Apr 09:36-> socket:[2305243589]

LRWX------1 root 09:36-> socket:[2305394065]

LRWX------1 root Apr 09:36-> socket:[2305394002]

We want to see the link state of the file descriptor for the socket. What do you think of that? Smart note there is a number "2305224138" in the back, where does this number come from? Spectators please look down.

The status information for all TCP links is saved under the/proc/net/tcp directory.

Copy Code

The code is as follows:

[root@xxxxxxx_10_1_17_138 song_test]# Cat/proc/net/tcp

SL local_address rem_address St Tx_queue rx_queue tr tm->when retrnsmt uid Timeout inode

0:8a11010a:7dc8 00000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 764789417 1 FFFF881051DFCB40 99 0 0 10-1

1:8a11010a:0369 00000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 737748331 1 ffff88106af8f7c0 99 0 0 10-1

51:8A11010A:FAF4 9c01010a:0cea 00000000:00000000 03:00000938 00000000 0 0 0 2 ffff8810516c01c0

52:8A11010A:21CD 0964010a:2227 00000000:00000000 00:00000000 00000000 0 0 2305224138 2 ffff8801402f55c0 23 3 30 10-1

53:8a11010a:fb8a 9c01010a:0cea 00000000:00000000 03:000012a8 00000000 0 0 0 2 ffff8810516c04c0

54:8a11010a:73e5 4511010a:0050 00000000:00000000 03:00000ea8 00000000 0 0 0 2 ffff88106898a880

55:8A11010A:89AD f300010a:1f90 00000000:00000001 00:00000000 00000000 0 0 2305271480 1 ffff880869b59740 23 3 0 10-1

187:8A11010A:0ACB 8811010a:1f90 00000000:00000000 03:0000028e 00000000 0 0 0 2 ffff881050e9ccc0

188:8a11010a:fb6c 9c01010a:0cea 00000000:00000000 03:000010CB 00000000 0 0 0 2 ffff88104fd8dd80

See the number "2305224138" No, is here, so we can find the link IP, Port link four Yuan group "8A11010A:21CD 0964010a:2227" This place is saved in hexadecimal, converted to decimal way " 10.1.17.138:8653 10.1.100.9:8743 ";

Go to the network connection state to look inside:

The code is as follows:

[root@xxxxxxx_10_1_17_138 song_test]# NETSTAT-NTP

Active Internet connections (w/o servers)

Proto recv-q Send-q Local address Foreign address State Pid/program Name

TCP 0 0 10.1.17.138:64428 10.1.1.156:3306 time_wait-

TCP 0 0 10.1.17.138:64244 10.1.1.156:3306 time_wait-

TCP 0 166 10.1.17.138:8653 10.1.100.9:8743 established 25465/./INDEX_SEARC

TCP 0 0 10.1.17.138:64394 10.1.1.156:3306 time_wait-

TCP 0 0 10.1.17.138:29669 10.1.17.69:80 time_wait-

TCP 0 0 10.1.17.138:46336 10.1.17.68:80 time_wait-

TCP 0 0:: ffff:10.1.17.138:8080:: ffff:10.1.17.136:27247 time_wait-

Back to the start question: The socket file descriptor represents a TCP connection to the local "10.1.17.138:8653" to "10.1.100.9:8743"!

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

11.11 Big Sale for Cloud

Get Unbeatable Offers with up to 90% Off,Oct.24-Nov.13 (UTC+8)

Get It Now >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.