header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
need guidance on setting process priority
Last Post 30 Jun 2010 08:25 AM by George Howarth. 9 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
tommlsUser is Offline
New Member
New Member
Posts:55
Avatar

--
30 Jun 2010 06:17 AM
    We have a batch file running every morning which does quite cpu-intensive calculations for about 2 hours.

    Could someone point me to how I can do the following??

    1. run the batch file's one and only command -- I assume that the existing batch file command will transfer over:

    C:\U\8\US\Bin\TransProc.exe -Um -P88 -S4 -L9 -CMLS -MBM

    2. then immediately set the transproc.exe process to LOW

    My guess is that the the script would be:

    C:\U\8\US\Bin\TransProc.exe -Um -P88 -S4 -L9 -CMLS -MBM
    (transproc.exe).priorityclass="Low" or "BelowNormal", whichever works best

    Or is there is another way where I could/should get the process ID of the TransProc.exe process, then set the process ID to Low??

    After the batch file is done the TransProc.exe file is done, no worries thereafter...

    Thank you, Tom
    George HowarthUser is Offline
    Basic Member
    Basic Member
    Posts:360
    Avatar

    --
    30 Jun 2010 06:30 AM
    You can do something like this:

    $startInfo = New-Object System.Diagnostics.ProcessStartInfo
    $startInfo.Arguments = "-Um -P88 -S4 -L9 -CMLS -MBM"
    $startInfo.FileName = "C:\U\8\US\Bin\TransProc.exe"

    $process = New-Object System.Diagnostics.Process
    $process.PriorityClass = [System.Diagnostics.ProcessPriorityClass]::BelowNormal
    $process.StartInfo = $startInfo

    $process.Start().WaitForExit()
    tommlsUser is Offline
    New Member
    New Member
    Posts:55
    Avatar

    --
    30 Jun 2010 06:38 AM
    wow...elegant...you are a PS ninja...!!

    I am not a programmer and my two-liner air code would have been my way of doing this...

    I can also see that this is quite re-usable code, in a true ninja style...!!

    Thank you..!!

    P.S. Do you have any suggestions how I can guarantee that PS really does wait over 2 hours for this process to finish?? and doesn't prematurely exit?? It's a super important calculation.
    George HowarthUser is Offline
    Basic Member
    Basic Member
    Posts:360
    Avatar

    --
    30 Jun 2010 06:44 AM
    WaitForExit() waits indefinately for the process to exit, so the script will only stop once it has received some sort of return value from it no matter how long that is.
    tommlsUser is Offline
    New Member
    New Member
    Posts:55
    Avatar

    --
    30 Jun 2010 06:50 AM
    OIC -- I looked it up to see what it does and also encountered complaints about it not working properly.
    George HowarthUser is Offline
    Basic Member
    Basic Member
    Posts:360
    Avatar

    --
    30 Jun 2010 07:12 AM
    Is there any particular reason why you need to keep the runspace ("script") alive once you've started the process?
    tommlsUser is Offline
    New Member
    New Member
    Posts:55
    Avatar

    --
    30 Jun 2010 07:18 AM
    Not longer than it takes to run the script, just not have the script stop calculating PRE-maturely.
    All the calculations must run every morning, start to finish.
    George HowarthUser is Offline
    Basic Member
    Basic Member
    Posts:360
    Avatar

    --
    30 Jun 2010 07:32 AM
    If the process stops prematurely, then that is the process' problem. All PowerShell is doing is starting it then off the process goes on its merry way. You do have the option inspecting the exit code however (which takes two possible forms), which can help with debugging:

    $process.Start().WaitForExit()
    $process.ExitCode

    OR

    $process.Start()
    Wait-Process -InputObject $process
    $process.ExitCode
    tommlsUser is Offline
    New Member
    New Member
    Posts:55
    Avatar

    --
    30 Jun 2010 07:48 AM
    OIC -- I can have a success message etc. like so??

    If $process.ExitCode = 0 then
    $body = Success;
    else
    $body = "fubar" + $process.ExitCode;

    send email
    George HowarthUser is Offline
    Basic Member
    Basic Member
    Posts:360
    Avatar

    --
    30 Jun 2010 08:25 AM
    Precisely.
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer