none
Force a Process to Raise its Priority via PowerShell - VirtualBox Guest RRS feed

  • Question

  • I know in VirtualBox's GUI you can allocate system resources to your VBox guests, but when attempting to raise the priority level of the process it throws an Access is Denied error. My steps:

        $a = get-process -name virtualbox


    which returns

        Handles  NPM(K)    PM(K)      WS(K)     CPU(s)     Id  SI ProcessName
        -------  ------    -----      -----     ------     --  -- -----------
             71       4     1180       2864       0.09   3672   1 VirtualBox
           1140     112   131344     131336      97.72   6712   1 VirtualBox
             75       4     2056       5236       0.19   9348   1 VirtualBox
            424      21    26156      33776       1.09  11304   1 VirtualBox

    The process can be verified with:

        $a[1].MainWindowTitle
         > Ubuntu Server [Running] - Oracle VM VirtualBox

    The process priority can usually be raised by running:

        $a[1].PriorityClass = [System.Diagnostics.ProcessPriorityClass]::RealTime

    In this specific case, it throws the following error:

        Exception setting "PriorityClass": "Access is denied"
        At line:1 char:1
        + $a[1].PriorityClass = [System.Diagnostics.ProcessPriorityClass]::Real ...
        + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            + CategoryInfo          : NotSpecified: (:) [], SetValueInvocationException
            + FullyQualifiedErrorId : ExceptionWhenSetting

    This is what I recovered from a 3 yo VirtualBox ticket:

        "Before the hardened security that was added to VirtualBox for Windows 
        (using VirtualBox 4.3.12 or prior), BOINC could easily manage/set/increase/decrease 
        the process priorities as needed.
    
        After the hardened security was added to VirtualBox for Windows (using VirtualBox
        4.3.14+), the process priorities can no-longer be controlled..."
    
        "It's not possible to change the priority with VirtualBox 4.3.28. 
        This still needs to be fixed, we are aware of this problem..."
    So it appears it's due to a security measure and VirtualBox is aware of it.

    Question: Is there a way to force a process to change its priority level through powershell without a 3rd party solution? 

    Raising the priority of the parent process (VBoxSVC) does not carry over to it as a child and from what I've seen and read the priority level of a process can not be set beforehand (I looked into ProcessStartInfo thinking there might be something configurable in there, but I read in a forum and inferred from Get-Member that was not the case). There might still be a way, I've just seen most conversations lead towards "set the priority after the process has started". 

    (Verification that VBoxSVC is the parent process; $a = VBoxSVC)

        Get-WmiObject win32_process | where {$_.ParentProcessId -eq $a.Id}
         > ...
         CommandLine                : "C:\Program Files\Oracle\VirtualBox\VirtualBox.exe" --comment "Ubuntu Server" ...
    I've also tried wmic process $a[1].Id CALL setpriority "realtime" which returned successfully, but checking the priority class the guest still remains at Normal.

    Saturday, July 21, 2018 11:27 PM

Answers

  • My overall goal isn't related to the question. I was asking if there was a way to force a process priority level to change through powershell. VirtualBox is an example but I'm sure others exist as well, if it's not possible - why is it not possible? It's not a problem that it isn't, I just want to be informed

    I recommend reviewing the SDK and system documentation on what process priority is.  You should never try to alter this unless you have well understood technical reasons for doing this.  This situation almost never occurs.

    Processes that require process boost will ask for it when needed.  The system also changes this as needed.  A process being scheduled from a return from an IO request automatically receives a process boost. A process that has been skipped by the scheduler due to another process gaining execution due to many things will receive an automatic scheduling priority boos,

    "Priority" is only a number that tells the scheduler how to choose the next process to schedule.  Changing the base priority can have negative effects on the process and on the system.  It is not a user adjustable property.


    \_(ツ)_/

    • Marked as answer by saniev Sunday, July 22, 2018 12:21 AM
    Sunday, July 22, 2018 12:17 AM

All replies

  • Can't be done and you don't want to alter process priority.  The system owns these processes and dynamically manages the priority as needed.

    Contact the vendor to learn how they recommend tuning VBox systems.


    \_(ツ)_/

    Saturday, July 21, 2018 11:48 PM
  • Ah so the access denied message is an indicator that the process is something that is managed by the system and can't be altered by the user? (In the case of this happening with a future process)
    Sunday, July 22, 2018 12:01 AM
  • What problem are you solving?

    -- Bill Stewart [Bill_Stewart]

    Sunday, July 22, 2018 12:06 AM
    Moderator
  • My overall goal isn't related to the question. I was asking if there was a way to force a process priority level to change through powershell. VirtualBox is an example but I'm sure others exist as well, if it's not possible - why is it not possible? It's not a problem that it isn't, I just want to be informed

    Though if this question did have to serve a purpose, I guess just that you'd have control over your system if there was a way and understand why/how you don't if there wasn't and could plan off of that. I like knowing how things work and this was an answer I couldn't

    • Edited by saniev Sunday, July 22, 2018 12:20 AM incomplete
    Sunday, July 22, 2018 12:10 AM
  • My overall goal isn't related to the question. I was asking if there was a way to force a process priority level to change through powershell. VirtualBox is an example but I'm sure others exist as well, if it's not possible - why is it not possible? It's not a problem that it isn't, I just want to be informed

    I recommend reviewing the SDK and system documentation on what process priority is.  You should never try to alter this unless you have well understood technical reasons for doing this.  This situation almost never occurs.

    Processes that require process boost will ask for it when needed.  The system also changes this as needed.  A process being scheduled from a return from an IO request automatically receives a process boost. A process that has been skipped by the scheduler due to another process gaining execution due to many things will receive an automatic scheduling priority boos,

    "Priority" is only a number that tells the scheduler how to choose the next process to schedule.  Changing the base priority can have negative effects on the process and on the system.  It is not a user adjustable property.


    \_(ツ)_/

    • Marked as answer by saniev Sunday, July 22, 2018 12:21 AM
    Sunday, July 22, 2018 12:17 AM
  • Here is the simple explanation of scheduling priority:

    https://docs.microsoft.com/en-us/windows/desktop/procthread/scheduling

    The "Windows Internal" book has a much more detailed explanation.


    \_(ツ)_/

    Sunday, July 22, 2018 12:20 AM
  • My overall goal isn't related to the question. I was asking if there was a way to force a process priority level to change through powershell. VirtualBox is an example but I'm sure others exist as well, if it's not possible - why is it not possible? It's not a problem that it isn't, I just want to be informed

    I recommend reviewing the SDK and system documentation on what process priority is.  You should never try to alter this unless you have well understood technical reasons for doing this.  This situation almost never occurs.

    Processes that require process boost will ask for it when needed.  The system also changes this as needed.  A process being scheduled from a return from an IO request automatically receives a process boost. A process that has been skipped by the scheduler due to another process gaining execution due to many things will receive an automatic scheduling priority boos,

    "Priority" is only a number that tells the scheduler how to choose the next process to schedule.  Changing the base priority can have negative effects on the process and on the system.  It is not a user adjustable property.


    \_(ツ)_/

    Thank you for this explanation! It was very informative and I'm reading through the documentation currently 
    Sunday, July 22, 2018 12:29 AM
  • The following will help you explore how the system sets processes:

    Running as an elevated Admin,

    get-process *|select Name, PriorityClass,PriorityBoostEnabled
    
    get-process |
        where{$_.PriorityClass -and $_.PriorityClass -ne 'Normal'} |
        select Name,PriorityClass,PriorityBoostEnabled

    Non-admins cannot view or alter priority.

    "Priority" is not viewable by normal means.  "PriorityClass" is the requested process priority but will not reflect the priority of the executing thread which can be altered by the process or by the system scheduler.

    "PriorityBoost" is generally enabled for all processes in the current versions of NT.  This allows the system to increase the scheduling priority for maximum efficiency and response.

    "Priority" is more related to services and system processes than it is to user processes.


    \_(ツ)_/



    • Edited by jrv Sunday, July 22, 2018 12:40 AM
    Sunday, July 22, 2018 12:34 AM
  • Monday, July 23, 2018 2:14 AM
    Moderator