[Nottingham] Unix process open sockets
Charles Samuels
charles at kde.org
Fri Jan 4 05:56:10 GMT 2008
Roger Light wrote, on Thursday 2008 January 03:
> Hi Phil,
>
> > Is there a way using perl that, given a process Id ($pid) I can
> > retrieve/display all the
> > associated sockets (unix/internet) of the corresponding unix process ?
>
> The answer has to be "yes", but I'm not sure how to do it natively. I
> suspect you might have to resort to looking in /proc/$pid but I don't
> know what for... :)
Hi there,
both netstat and lsof are implemented in terms of /proc/$pid - there's really
no other way to do it.
You map the contents of each of the symlinks in /proc/$pid/fd/ to a file
in /proc/net/... - it's not exactly easy
> Both netstat (with "netstat -ap") and lsof can retrieve this
> information, so you could always either look at how they do it or parse
> their output.
I think parsing their output is the way to go.
Good luck, and tell us how you decided to do it and what it's for!
charles
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
Url : http://mailman.lug.org.uk/pipermail/nottingham/attachments/20080104/eaf14c99/attachment.bin
More information about the Nottingham
mailing list