Thread: Limiting another program from taking to much of system

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    155

    Limiting another program from taking to much of system

    Hi, I was wounding if C++ could limit what another program can do with in it self. Like I want to limited how much space, ram and cpu usage a program can use inside its self, for a exm. Program B --inside> Program A, but Program B is limited to only 1mb of ram 1mb of space and like can only use maxs of 10% or lower of the cpu to do stuff in? If not, can windows, and if so can this post please be move to windows?

  2. #2
    Registered User
    Join Date
    Dec 2004
    Posts
    465
    I don't know of anything that can do this but if you go into processes in the task manager, you can set priority by right clicking the process.
    My computer is awesome.

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    C++ can't do it. Windows might be able to do it. Unix-type OSs can do it. It's called quotas, so searching for this would be profitable.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #4
    Registered User
    Join Date
    Dec 2005
    Posts
    155
    Hmmm i'll have to look harder then, and if you dont get why I am asking is, I have a program that takes around over 80-90% of the cpu (I have a 2.4GHz, 1 core) so I only want it to see like maybe 1.9 or so of that GHz witch will trick the program thinking thats my limit leaving me more cpu for me to run other programs....or trying to make it do, lol. If you come across any code for it do post the website or code for me too see, still googling it.
    Last edited by adr; 06-30-2007 at 06:39 AM.

  5. #5
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    If you can make your program block at times instead of busy-wait, that might solve some issues, Otherwise, you can programatically make the program stop working every so often by forcing it to sleep, but I think that to be a poor choice if you can avoid it.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Setting the process priority to something lower than normal would be the thing to do.

    Ideally, you want your program to have as much CPU as possible when there is absolutely nothing else to do.

    But if there is something more important, like any of your normal apps, then the OS should stop running your background program and run your normal programs.
    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.

  7. #7
    Registered User
    Join Date
    Dec 2005
    Posts
    155
    Quote Originally Posted by Salem View Post
    Setting the process priority to something lower than normal would be the thing to do.

    Ideally, you want your program to have as much CPU as possible when there is absolutely nothing else to do.

    But if there is something more important, like any of your normal apps, then the OS should stop running your background program and run your normal programs.
    Ideally yes, but if a program thinks it only has so much (meaning it thinks the CPU is 1.9 GHz, 1mb of ram, 1mb of memory so on) and is ever crash or something else's (meaning if the program stop responding) it will only take what I give it up, not the rest of the computer making it easier to just shut the program down (going to control manger) and or letting other programs run till everything fixes (reg. cleaner). Why I kinda want to limit its processing power and other things, kinda like a safety lock.
    Last edited by adr; 06-30-2007 at 10:22 PM. Reason: Someone cant read english O.o

  8. #8
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    ...?

    can you edit that to use better grammar?

    edit:

    I think you mean like a resource cap, meaning you specify a specific limit for memory usage or cpu usage, and the program doesn't go beyond that?
    Last edited by robwhit; 07-01-2007 at 12:36 PM. Reason: I can't read english

  9. #9
    Registered User
    Join Date
    Dec 2005
    Posts
    155
    Quote Originally Posted by robwhit View Post
    ...?

    can you edit that to use better grammar?

    edit:

    I think you mean like a resource cap, meaning you specify a specific limit for memory usage or cpu usage, and the program doesn't go beyond that?
    LOL, yes, what I been saying... O.o; can windows or even C++? I know you can go and change the priority or use the sleep funtion but it doesnt limit anything really.
    Last edited by adr; 07-02-2007 at 01:39 AM.

  10. #10
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    but it doesnt limit anything really.
    Do not be so sure...
    Write a program that eats all the CPU
    and run it with RT priority and with Idle priority
    And see if you can kill it using Task manager... I dobt that the results will be the same
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. using system command results in a program
    By finnepower in forum Windows Programming
    Replies: 6
    Last Post: 06-10-2005, 08:58 AM
  2. system commands. deletion of file after program terminates
    By xddxogm3 in forum C++ Programming
    Replies: 12
    Last Post: 11-24-2003, 10:41 PM
  3. How do I put my program into the system tray?
    By kinghajj in forum Windows Programming
    Replies: 1
    Last Post: 11-05-2003, 07:56 PM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM