Sign in to follow this  
Followers 0
Gibbo

Limiting number of processes

1 post in this topic

I hope this will be of use to someone.

I recently had to do a batch job (applying EXIF data to photos) that wasn't very processor intensive. Running the command ("program.exe" in the code below) with "RunWait" was just too slow, but running it with "Run" spawned some 5000+ processes, bringing the pc to a grinding halt.

After some fiddling I came up with the code below.

I am sure there is a more elegant solution, and it would be nifty to translate it to a function or some such, but it works as is quite well.

Let me know if you have any questions or improvements :)

#include <array.au3>
Const $iMaxProcesses = 5
Dim $aPIDs[1]

For $sItem In $aLotsofitems
    While UBound($aPIDs) > $iMaxProcesses
        For $thePID In $aPIDs
            $iResult = ProcessWaitClose($thePID, 1)
            If $iResult Then
                _ArrayDelete($aPIDs, _ArraySearch($aPIDs, $thePID))
                ExitLoop
            EndIf
        Next
    WEnd
    $pid = Run("program.exe " & $sItem)
    _ArrayAdd($aPIDs, $pid)
Next

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0