How can I load a cpu a certain percentage?

This is a discussion on How can I load a cpu a certain percentage? within the C Programming forums, part of the General Programming Boards category; I have to simulate load on a computer. Ideally what I would like to do is be able to manipulate ...

  1. #1
    Registered User
    Join Date
    Jun 2005
    Posts
    10

    Question How can I load a cpu a certain percentage?

    I have to simulate load on a computer. Ideally what I would like to do is be able to manipulate the load on the computer, ie load it to like 20% per instance running. Or be able to vary it within the code.

    So far my approach has been to create an infinite loop that will load the cpu to 100% and then introduce a variable pause, but I have found this difficule to achieve.

    The code is roughly

    //infinite loop
    usleep(100);

    Also I would like to be able to do the same sort of loading with the disk, which I have something that will write a series of numbers then read them again, then proceed to rewrite them.

    Neither of these have worked for me, any pointers in the right dircection.

    Thanks,
    Nick

  2. #2
    Jez
    Jez is offline
    The C-er
    Join Date
    Mar 2004
    Posts
    192
    So you want to falsify the system monitor metrics.... Why?

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    10
    I would rather not falsify it, but use system resources doing useless tasks.

    It would be in order to test how an app performs with limited resources, ie does it hang, crash, or just degrade in performance.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,340
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    Jun 2005
    Posts
    10
    Yeah its pretty much like that.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. questions on multiple thread programming
    By lehe in forum C Programming
    Replies: 11
    Last Post: 03-27-2009, 07:44 AM
  2. Sleep() causing unexplained reduction in cpu load
    By sajanphilip in forum C++ Programming
    Replies: 4
    Last Post: 02-26-2008, 01:58 AM
  3. retrieving current CPU load
    By kristy in forum C Programming
    Replies: 2
    Last Post: 11-30-2003, 08:30 AM
  4. Accessing CPU load using C in Windows
    By srpathak in forum C Programming
    Replies: 1
    Last Post: 10-31-2003, 03:59 AM
  5. Accessing CPU load in Windows using C
    By srpathak in forum Windows Programming
    Replies: 2
    Last Post: 10-31-2003, 02:23 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21