Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tracing socket (file) descriptor back to bound address

Tags:

c

c#

linux

mono

I have a running application (C#/mono) which appears to be looping on the following system call : (I determined this via a run of strace and found that this call is currently the only being made)

recvfrom([sockfd], "", [length], 0, NULL, NULL)   = 0

Reading up on recvfrom (http://linux.die.net/man/2/recvfrom) I find the first parameter sockfd to be representative of a socket file descriptor.

Without stopping the application and including debug logic / extra verbosity to let me know which socket address the sockfd has been bound to, is there any way to look this up?

I've tried poking around for any references of where this information may be made available from the system but haven't come up with much

Thanks in advance,

like image 675
Michael Di Felice Avatar asked Jan 28 '26 07:01

Michael Di Felice


1 Answers

You can use the lsof command to list all open IP sockets for a program doing like this

lsof | grep pid.*sd.*IP

where

  • pid is to be replaced by the program process id and
  • sd is to be replaced by the socket descriptor as shown by strace.
like image 69
alk Avatar answered Jan 29 '26 20:01

alk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!