set to below priority for windows

This is a discussion on set to below priority for windows within the Windows Programming forums, part of the Platform Specific Boards category; Hello, I am writing my program for windows and I am wondering how I can make my program run below ...

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    12

    set to below priority for windows

    Hello,

    I am writing my program for windows and I am wondering how I can make my program run below low priority. If you know the code to set do this please let me know.

    thanks.

  2. #2
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Wrong section, should be in Windows programming... But:
    http://msdn2.microsoft.com/en-us/library/ms686219.aspx

  3. #3
    Registered User
    Join Date
    Apr 2007
    Posts
    12
    Hello,

    I've tried that link above but I can't get it to work. I don't think I am doing it right. How do I implment it in C/C++

    thanks.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,558
    Maybe post your attempt, and try to come up with something better than "doesn't work".
    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
    Apr 2007
    Posts
    12
    getdisk.cpp:32: error: `PROCESS_MODE_BACKGROUND_BEGIN' undeclared (first use
    this function)
    getdisk.cpp:32: error: (Each undeclared identifier is reported only once for
    each function it appears in.)
    getdisk.cpp:35: error: `ERROR_PROCESS_MODE_ALREADY_BACKGROUND' undeclared
    (first use this function)
    getdisk.cpp:38: error: label `Cleanup' used but not defined

    getdisk.o - 4 error(s), 0 warning(s)


    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <windows.h>
    
    int main(){
    
    DWORD dwError, dwPriClass;
    	
    	if(!SetPriorityClass(GetCurrentProcess(), PROCESS_MODE_BACKGROUND_BEGIN))
       {
          dwError = GetLastError();
          if( ERROR_PROCESS_MODE_ALREADY_BACKGROUND == dwError)
             printf("Already in background mode\n");
          else printf("Failed to enter background mode (%d)\n", dwError);
          goto Cleanup;
       } 
    
       // Display priority class
    
       dwPriClass = GetPriorityClass(GetCurrentProcess());
    
       printf("Current priority class is 0x%x\n", dwPriClass);
    
      return 0;
    }

  6. #6
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Background processing is only available on Vista. Even if you have Vista, it will probably require an update to your header and library files. You could use BELOW_NORMAL_PRIORITY_CLASS or IDLE_PRIORITY_CLASS instead.

  7. #7
    Registered User
    Join Date
    Apr 2007
    Posts
    12
    I'm searching google for BELOW_NORMAL_PRIORITY_CLASS but haven't found any good documentation. can you recommend a source?

    or let me know the small snip of code that will set my program to run in below low priority.

    thanks.

  8. #8
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Code:
    SetPriorityClass(GetCurrentProcess(), BELOW_NORMAL_PRIORITY_CLASS);
    should do it.

  9. #9
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    to read more about process and thread priorities - you can look at this: http://msdn2.microsoft.com/en-us/library/ms685100.aspx
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  10. #10
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    Code:
    BOOL SetPriorityClass(
      HANDLE hProcess,        // handle to process
      DWORD dwPriorityClass   // priority class
    );
    dwPriorityClass is one of the following:

    REALTIME_PRIORITY_CLASS
    HIGH_PRIORITY_CLASS
    ABOVE_NORMAL_PRIORITY_CLASS
    NORMAL_PRIORITY_CLASS
    BELOW_NORMAL_PRIORITY_CLASS
    IDLE_PRIORITY_CLASS


    be very careful with REALTIME_PRIORITY_CLASS . if your program uses a lot of cpu cycles it can hog your entire processor, preventing windows from responding even to the 3 finger salute.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  11. #11
    Math wizard
    Join Date
    Dec 2006
    Location
    USA
    Posts
    582
    Windows Task Manager, by default, is at high priority. If using high priority, I suggest putting Windows Task Manager to "Realtime" priority to make it easier to close (right-click on the process (taskmgr.exe) and choose set priority > Realtime to do so). If you encounter an infinite loop without doing this and realtime is set for your program and WTM is only high, you're doomed. I just thought I'd point this potential "hazard" out.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Priority queue
    By cjwenigma in forum C++ Programming
    Replies: 6
    Last Post: 12-03-2007, 12:30 AM
  2. Replies: 7
    Last Post: 08-19-2007, 08:10 AM
  3. The new FAQ
    By Hammer in forum A Brief History of Cprogramming.com
    Replies: 34
    Last Post: 08-30-2006, 10:05 AM
  4. problem with open gl engine.
    By gell10 in forum Game Programming
    Replies: 1
    Last Post: 08-21-2003, 04:10 AM
  5. Set default directory with GetTempDir?
    By Bajanine in forum Windows Programming
    Replies: 2
    Last Post: 05-04-2003, 11:36 PM

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