In case 1, you're essentially asking Perl to, as fast as it can, keep checking to see if a key has been pressed. This means that your program is constantly in a 'Run' state, unless forced to give up the CPU for another program.

In fact, that's what's helping to cap the process's CPU utilization. The scheduling algorithm (one of them, anyway - Solaris has several) in the kernel is forcing your program to temporarily give up the CPU, and your process is being rescheduled with a lower priority because it's asking to do so much, meaning it'll take it an extra bit of time to make its way back onto the CPU.

If you voluntarily give up the CPU, by blocking on a resource or by sleep()ing, you get scheduled with a higher priority than those who don't. Which is another factor leading toward why your keyboard response times don't drop - processes that spent a lot of time blocked on IO functions manage to get higher priority.


Hope this serves to illuminate...

--jwest

-><- -><- -><- -><- -><-
All things are Perfect
    To every last Flaw
    And bound in accord
         With Eris's Law
 - HBT; The Book of Advice, 1:7

In reply to Re: Sleep, don't Weep by jwest
in thread Sleep, don't Weep by jlongino

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.