in reply to how to occupy the processor for a fixed percentage of it
However, over a given time period, you can have had N%, 0 <= N <= 100, of the available CPU time. To archieve that, just before finishing the program, measure how much CPU time the program has had, how much time has passed, and calculate how long you have to sleep before doing the exit. But remember, you cannot sleep negative time. Instead of sleeping, you may have to doing a lot of work to increase the average CPU time (if the machine is busy, this may require the process get root permission and kill other processes, and/or decrease its niceness, so it can get more or longer time slots).
Calculations can get more hairy if you have more than 1 processor, and more threads. And ambiguous. Does 100% CPU time mean using the full power of all CPUs, or just the equivalent of one?
|
|---|