Regarding TIME_WAIT, you got me there, I didn't actually suspect they might be closed and timing out, is this normal behaviour?

Yes. A TCP port is marked as unavailable (TIME_WAIT) for an amount of time after being closed to avoid having a delayed packet from one connection affect a later connection on the same port. This can be disabled on a per-socket basis (at least).

Are there any ways for me to report number of sockets being kept open within perl?

I sure there is, but I don't know what tools are available.

On some systems, you could peek into /proc/$$/fd/ ($$ representing the process's PID). You'll see open file handles, which includes open sockets.

$ perl -MIO::Socket::INET -E' system "ls -lF /proc/$$/fd/"; my $s = IO::Socket::INET->new("www.google.com:80") or die $!; system "ls -lF /proc/$$/fd/"; ' total 0 lrwx------ 1 eric users 64 Feb 14 15:22 0 -> /dev/pts/7 lrwx------ 1 eric users 64 Feb 14 15:22 1 -> /dev/pts/7 lrwx------ 1 eric users 64 Feb 14 15:22 2 -> /dev/pts/7 lr-x------ 1 eric users 64 Feb 14 15:22 3 -> pipe:[2358130] total 0 lrwx------ 1 eric users 64 Feb 14 15:22 0 -> /dev/pts/7 lrwx------ 1 eric users 64 Feb 14 15:22 1 -> /dev/pts/7 lrwx------ 1 eric users 64 Feb 14 15:22 2 -> /dev/pts/7 lr-x------ 1 eric users 64 Feb 14 15:22 3 -> socket:[2358143] lr-x------ 1 eric users 64 Feb 14 15:22 4 -> pipe:[2358144]

(0,1,2 = std*. The pipe is used by system to communicate exec failures to the parent.)

Update: netstat on my machine has a -p option that shows the PID of the process that owns the socket.


In reply to Re^3: limiting the amount of sockets opened by f by ikegami
in thread limiting the amount of sockets opened by f by Faile

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.