Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | James Kuyper <jameskuyper@verizon.net> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Question of throttling CPU usage |
| Date | 2012-04-25 14:44 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <4F984620.8000006@verizon.net> (permalink) |
| References | <6e2a5c39-7a60-4ce1-a609-4211213782bc@er9g2000vbb.googlegroups.com> |
On 04/25/2012 02:22 PM, jon.harding@gmx.co.uk wrote:
> Hi, can someone help with how I can throttle CPU usage in a c
> application.
>
> By means of an example, in this trivial application
>
> int main(int argc, char *argv[]) {
> int i;
> while (1) {
> i++;
> }
> }
>
>
> how can I limit the CPU usage for the loop to be 10% or 20% or 50% or
> whatever integer I pass in on the command line.
The C standard provides no mechanism for doing this; whether there is
any such mechanism, and how to use it, will depend upon your operating
system.
For instance, on unix-like systems:
sleep() provides a mechanism for relinquishing control of the CPU for a
period of time; To achieve a desired percentage of the time, use calls
to clock() to determine when the next time should be for a call to sleep().
If all you really want is to reduce your CPU usage, without needing
precise control over reduction, call the nice() function to lower the
scheduling priority for your process.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Question of throttling CPU usage jon.harding@gmx.co.uk - 2012-04-25 11:22 -0700
Re: Question of throttling CPU usage James Kuyper <jameskuyper@verizon.net> - 2012-04-25 14:44 -0400
Re: Question of throttling CPU usage jon.harding@gmx.co.uk - 2012-04-25 12:35 -0700
Re: Question of throttling CPU usage Thomas Richter <thor@math.tu-berlin.de> - 2012-04-25 21:39 +0200
Re: Question of throttling CPU usage James Kuyper <jameskuyper@verizon.net> - 2012-04-25 15:59 -0400
Re: Question of throttling CPU usage jon.harding@gmx.co.uk - 2012-04-25 15:33 -0700
Re: Question of throttling CPU usage Ian Collins <ian-news@hotmail.com> - 2012-04-26 10:37 +1200
Re: Question of throttling CPU usage jon.harding@gmx.co.uk - 2012-04-26 01:41 -0700
Re: Question of throttling CPU usage Robert Wessel <robertwessel2@yahoo.com> - 2012-04-26 04:25 -0500
Re: Question of throttling CPU usage James Kuyper <jameskuyper@verizon.net> - 2012-04-26 06:59 -0400
Re: Question of throttling CPU usage Robert Miles <milesrf@Usenet-News.net> - 2012-05-27 23:35 -0500
Re: Question of throttling CPU usage Nobody <nobody@nowhere.com> - 2012-04-26 14:33 +0100
Re: Question of throttling CPU usage Fred K <fred.l.kleinschmidt@gmail.com> - 2012-04-26 07:44 -0700
Re: Question of throttling CPU usage James Kuyper <jameskuyper@verizon.net> - 2012-04-26 11:45 -0400
Re: Question of throttling CPU usage Nobody <nobody@nowhere.com> - 2012-04-26 14:27 +0100
Re: Question of throttling CPU usage tom st denis <tom@iahu.ca> - 2012-04-26 12:01 -0700
Re: Question of throttling CPU usage Robert Miles <milesrf@Usenet-News.net> - 2012-05-27 23:19 -0500
Re: Question of throttling CPU usage Lanarcam <lanarcam1@yahoo.fr> - 2012-04-25 21:39 +0200
csiph-web