Thread: How can I load a cpu a certain percentage?

  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
    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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    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.

  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, 02:58 AM
  3. retrieving current CPU load
    By kristy in forum C Programming
    Replies: 2
    Last Post: 11-30-2003, 09:30 AM
  4. Accessing CPU load using C in Windows
    By srpathak in forum C Programming
    Replies: 1
    Last Post: 10-31-2003, 04:59 AM
  5. Accessing CPU load in Windows using C
    By srpathak in forum Windows Programming
    Replies: 2
    Last Post: 10-31-2003, 03:23 AM