in reply to how to occupy the processor for a fixed percentage of it
You need a method to sleep in the subsecond range. 'perldoc sleep' mentions two methods for doing that
Then you have two possibilities:
1) Do a feedback loop. You need fine-grained measurement of cpu usage, on linux you could check out whether the /proc directory offers suitable information (ps gets its usage information from there AFAIK). Sleep a millisecond if you are above 80%, or do a loop for some time (doesn't really matter how long) if you are below. Loop over that
2) sleep and work in a fixed ratio.You need a method to loop for a fixed subsecond time (perldoc alarm tells you of a few methods, basically the same as for sleep). Then just work and sleep in a ratio of 80 to 20, if you want 80% utilization
|
|---|