awohld has asked for the wisdom of the Perl Monks concerning the following question:

I have a data intensive script. During the Heavy CPU part I want to drop the run-time priority level low, then put it back to 0 at another time. Is this how you can change the run-time priority level of a script from within the script itself?
#!/usr/bin/perl -w use strict; # What's my priority level? my $pri = getpriority(0, 0); print "My priority level is: $pri\n"; # Set priority level 6 for this script. setpriority(0, 0, 6); # What's my new priority level? $pri = getpriority(0, 0); print "My priority level is: $pri\n";

Replies are listed 'Best First'.
Re: Altering scripts execution priority level from within a script.
by ambrus (Abbot) on Jun 11, 2006 at 17:03 UTC

    In unix, you can lower the priority level but raise it only if you are root. You have to fork a lower priority process if you want to return to normal priority.

Re: Altering scripts execution priority level from within a script.
by zentara (Cardinal) on Jun 12, 2006 at 12:14 UTC
    I know it's obvious, but maybe you can setup some clever sleep sub, which detects system load, and computes an appropriate amount to sleep periodically in the data-intensive portion of your script?

    I'm not really a human, but I play one on earth. flash japh