Is there any way to lookup the send/receive buffer sizes for TCP sockets?
I've poked around with both netstat and ss, as well as the raw /proc/net/tcp. Lots of goodies there, including the counts of bytes in flight, timers, process name, etc.
But I'd like to be able to diagnose whether some proceses are setting SO_{SND,RCV}BUF...and more interestingly what values the kernel is actually using for each SKB.
From the lsof FAQ (search for "Why doesn't lsof report socket options"), I believe Linux doesn't make the info you're after available. (at least not via /proc)
If it did, you could use
lsof -i <pid> -a -i tcp -T f
, but -T only takes "qs", not f on Linux. You can get some other info from netstat (netstat --tcp -p -o -e -e -v | grep <pid>
) which includes the Send Queue and Receive Queue and some timer info.What you could do is use strace. You'd have to either run the program via strace (
strace -ff -e network,ioctl PROGRAM
) or before it sets up the TCP socket (strace -fff -e network,ioctl -p PID
).ioctl
is how those options would be set, andnetwork
should catch enough to tell what connections those are. (but just ioctl and then use lsof to figure out where the connections to should work, too)You can actually do that using
https://github.com/veithen/knetstat
.E.g. for
nc -I 8192 -O 8192 www.google.com 80
this would give (see theSO_RCVBUF
andSO_SNDBUF
on the third row):You can change the size of the receive and the send buffer as follows (send buffer shown):
and to get the current size, use:
There is a known bug in Linux that reports the current buffer size as 1/2 the set value. I can't remember if the internal value is 1/2 of what was requested, or whether the report is 1/2 of what it really is.