in reply to Setting CPU usage limit with BSD::Resource
There's no way you can set CPU usage to a percentage of CPU time. Anyway, you don't want to do that, because it would mean that your CPU would idle some of the time while at other times it still cannot perform the other (more important) tasks. What you want is for your script to use the CPU 100% when no other task is waiting to be run, but to release the processor when another process needs it.
The way this is done in *NIX is the process priority (otherwise known as the "nice" value). This is a value between -20 (highest priority, process is prioritized over all other processes) and 19 (lowest priority). Process priority can be set either on the commandline vie the "nice" or "renice" commands, e.g.
nice -n 10 perlscript.pl # or, if the process is already running renice 10 -p <PID>
(see the man pages for these commands for more details). Or with the BSD::Resource module method setpriority
use BSD::Resource; my $success = setpriority(0,10);
|
|---|