Thread: controlling the processor resources

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    17

    controlling the processor resources

    Does anyone know how I can keep my program from using 99% of my cpu percentage every time I run it? Is there a way to set some kind of limit, like say 10%?

    I have looked at <sys/resource.h> extensively, and all I have found is that it only allows the setting of memory limits.

    Please tell me if I have missed something or please point me in the direction of a header that does this.

    Thanks so much!
    Last edited by nadamson6; 09-30-2005 at 10:28 PM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Which OS and compiler?
    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.

  3. #3
    Unregistered User
    Join Date
    Sep 2005
    Location
    Antarctica
    Posts
    341
    If you are on windows, there are windows API calls like SetThreadPriority. I haven't used them in years, but check msdn.

  4. #4
    Registered User
    Join Date
    Sep 2005
    Posts
    17
    I am currently using FreeBSD unix... but I would like to control it on any *nix. Also I am using GCC 3.45.

    Thanks

  5. #5
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    The easiest way would be to call usleep every so often.

  6. #6
    Unregistered User
    Join Date
    Sep 2005
    Location
    Antarctica
    Posts
    341
    try looking into the pthread library, there may be something in there for setting process/thread priorities

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    $ man 2 nice
    $ man 2 setpriority
    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.

  8. #8
    Unregistered User
    Join Date
    Sep 2005
    Location
    Antarctica
    Posts
    341
    ah yes, nice, forgot about that one. I had to use that once a couple years ago.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Controlling a trackbar
    By bigdan43 in forum C++ Programming
    Replies: 1
    Last Post: 08-24-2005, 11:24 AM
  2. Controlling Repetition in a Structure
    By Silence in forum C Programming
    Replies: 2
    Last Post: 08-23-2002, 05:35 PM
  3. Controlling terminal tty
    By pdstatha in forum C Programming
    Replies: 0
    Last Post: 04-02-2002, 03:57 AM
  4. Controlling the parallel port in C++
    By Monkey_Drone in forum C++ Programming
    Replies: 3
    Last Post: 02-06-2002, 08:18 PM
  5. controlling pitch and duratio of \a
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 10-10-2001, 08:31 PM