panku55:

One simple way to write script for CPU utilization would be something like this:

#!/usr/bin/perl use strict; use warnings; while (1) { }

However, that may not use enough CPU. You might try forking off a few dozen processes and have each of them slaving away on the busy loop. But as computers get faster and faster, one day soon an infinite loop will execute in just a few seconds. So I suggest you wrap the busy loop inside a few other busy loops to keep them running:

#!/usr/bin/perl use strict; use warnings; while (1) { while (1) { while (1) { while (1) { } } } }

Modern computers also have segmented themselves into various sections. The busy loop will keep the control-flow part of your CPU busy, but it won't do anything at all for your integer, logic and floating-point sections. So to give them some exercise, you'll want to add some other bits of work to do:

#!/usr/bin/perl use strict; use warnings; my ($april, $fools) = (0, 0); while (1) { while (1) { while (1) { while (1) { if (rand > .5) { if (rand > .5) { $april *= .7 } else { $april /= . +5 } if (rand < .5) { $april += 4.5} else { $april -= 3 +.2 } } if (rand > .5) { if (rand > .5) { $fools *= 3 } else { $fools %= 13 + } if (rand < .5) { $fools += 5 } else { $fools -= 11 + } } } } } }

Feel free to add some code to exercise the transcendental functions as well. Additionally, if you want increase your printer utilization as well, you might fork off a version of this code that prints its results. With a few more modules, you can increase your network utilization as well!

...roboticus

When your only tool is a hammer, all problems look like your thumb.


In reply to Re: cpu utilization for unix os by roboticus
in thread cpu utilization for unix os by panku55

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.