O Monks,

I have a cgi script that is kind of a cpu hog. Some of the people using it are my students, and I want to make sure it's fast for them. Other people using it are people I don't know, and I'd like them to get a smaller share of CPU time.

I can do this:

use POSIX ();
if ($not_my_student) {
  POSIX::nice(17);
}

What worries me a little is that the nice() function behaves cumulatively. To make the whole thing really bulletproof and portable, I'd like to be able to figure out what my process's current priority is, and make sure that I never nice it down to such a low priority that it starves for CPU, or gets terminated (which I believe can happen on at least some Unixes if your priority is low enough). I don't want to make any assumptions, for instance, about what basic priority Apache is running at.

I can't seem to find anything in the POSIX module that lets me find out my current priority. Is there any way to do this without crufty platform-specific calls to external scripts?

TIA!


In reply to knowing what niceness level you're starting from with POSIX::nice() by bcrowell2

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.