Hello, I am using a WHILE(1) that is used by the script to poll a ip address/port continously but we do not like that it is using 100% CPU. Is ther anthing that can be done as this script needs to poll 24/7. We were thinking about using the sleep but were afraid we would lose transactions. Does nyone have any ideas on modifying the script to not use 100% CPU%? Here is the part of the script with the WHILE:
while (1) { # Continously Listening on Port for connections my ($rh_set) = IO::Select->select($read_set, undef, undef, 0); foreach $rh (@$rh_set) { print "Process each handle...\n"; print "Main socket connection..\n"; $ns = $rh->accept(); $read_set->add($ns); }else{ print "Ordinary socket, read...\n"; my $bytecount = sysread($rh, $buf, 1024); $iroam_req_type = substr($buf,0,8); if($buf) { print " *** BEGIN PROCESSING CALL ***"; print "Iroam transaction received:\n"; print "$buf\n"; if ($iroam_req_type =~ /FindMin/){ $find_min_request_rec = $buf; }elsif ($iroam_req_type =~ /PriceCal/){ $price_call_rec = $buf; } pass_transaction_to_iroam_package(); print "Sending Response....\n"; $rh->send($iroam_response_rec); }else { print "Iroam client closed socket..\n"; $read_set->remove($rh); close($rh); } } }

In reply to While(1) using 100% CPU by crawfordr

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.