1

I want to get the socket descriptor reference count. Where is this count stored? I didnt find it in inode structure. How can I get this value?

aaa
  • 415
  • 6
  • 15

1 Answers1

0

It is available per protocol, in /proc/net/* files.

For instance, the official /proc/net/tcp documentation indicates there is a socket reference count column, just after the inode value. See https://askubuntu.com/a/243441

$ cat /proc/net/tcp
sl  local_address rem_address   st tx_queue rx_queue tr tm->when retrnsmt   uid  timeout inode                                                     
 0: 0100007F:0CEA 00000000:0000 0A 00000000:00000000 00:00000000 00000000   115        0 14759 1 0000000000000000 100 0 0 10 -1

Here the inode is 14759, and the socket reference count is 1.

There is a similar ref column for UDP - see https://stackoverflow.com/a/18322579/458259

$ cat /proc/net/udp   
  sl  local_address rem_address   st tx_queue rx_queue tr tm->when retrnsmt   uid  timeout inode ref pointer drops             
  40: 00000000:0202 00000000:0000 07 00000000:00000000 00:00000000 00000000     0        0 3466 2 ffff88013abc8340 0           

Here the inode is 3466, and the socket reference count is 2.

Note that only newer kernels do have this socket reference count column information.

Arnaud Bouchez
  • 42,305
  • 3
  • 71
  • 159