The following is for Linux (and should work this way on most *NIXes).

To have your program use one core only all you need to do is run it without forking. The OS will automatically give you as much CPU time on a single core as it can without detrimentally affecting the rest of the system. This means that, unless you're on a system that is heavily loaded by multiple processes (or your program is I/O-bound) your program will always run at 99% or 100% CPU usage on a multi-core machine. If you find that the OS scheduler occasionally assigns other tasks to the core your program is using (if e.g. you're on a desktop system which has several programs you're using interactively) you can change the process priority (the "nice" value) via the inbuilt setpriority(e.g. setpriority 0,$$,1)

For running your process on multiple CPU cores, simply fork it into as many processes. Again, the OS will take care of running your processes efficiently. Executing setpriority prior to forking will pass the nice value on to the process children.


All dogma is stupid.

In reply to Re: use dual-core or quad-core by tirwhan
in thread use dual-core or quad-core by baxy77bax

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.