On 4/26/2012 5:59 AM, James Kuyper wrote:
> On 04/26/2012 04:41 AM, wrote:
>> On Apr 25, 11:37�pm, Ian Collins<ian-n...@hotmail.com> wrote:
>>> On 04/26/12 10:33 AM, jon.hard...@gmx.co.uk wrote:
>>>
>>>>>>> On 04/25/2012 02:22 PM, jon.hard...@gmx.co.uk wrote:
>>>
>>>>>>>> Hi, can someone help with how I can throttle CPU usage in a c
>>>>>>>> application.
>>>
>>>> OK, I understand. I am new to c.
>>>
>>>> Let me put it this way, can I do what I want in c++? I don't know that
>>>> language either, but I may as well learn the one that will let me do
>>>> what I want.
>>>
>>> No. �The same conditions apply.
>>>
>>> If you want to manage CPU utilisation, it has to be done either outside
>>> of the application, or in a system dependent way.
>>>
>>> --
>>> Ian Collins
>>
>> OK, and I am sorry to labour the point here, but how can I do this
>> outside the application then?
>
> I think "system dependent" rather than "outside the application" is your
> best bet, given the following requirements.
>
>> Here are the requirements:
>> 1. My program will run hopefully on Windows and Linux.
>> 2. My program should run at a set CPU percentage and not exceed it.
>> 3. The CPU percentage may be different depending on the time of day;
>> ie after 6pm and over a lunch break 12:30 - 1:00pm it will run at 85%
>> utilization, but at other times around 10%
>
> For the Linux side, we've already discussed how clock() and sleep()
> could be used to manage your CPU percentage. localtime() provides the
> mechanism for making the % vary with time of day.
>
> For Windows, I can't help you - I haven't had to program for that
> environment in nearly two decades. But Robert Wessel seems to have dealt
> with that side.
I've used the Cygwin Linux-emulation under Windows, and it provides
clock(), sleep(), and localtime(). Use the info command for locating
details on how to call each of them.
Robert Miles