Jump to content
Sign in to follow this  

Need for multi-process management

Recommended Posts

I am looking for some design ideas for multi-process management (or perhaps a current udf that fits my needs). My script design has a main script that runs other small .exe with command line options. I could be calling up to 100 other exe so a simple loop would call all 100 processes to quickly slowing the computer down and a using a runwait could take to long to run thru all of them. I am hoping to come up with a way to run 10 or so process at a time and when one process ends another one will start. I know that I have no code here as I am looking for design ideas. I have no working version other than my simple loop which will most likely require a total rewrite if the community can help me come up with a solution. Any ideas?

Share this post

Link to post
Share on other sites

If the processes are your own scripts I would advise you to combine them into one executable with allot of functions that can be called conditionally. Even if the functions can only be ran one at the time it's probably allot faster than loading a new executable for each one. Otherwise the script below should be a step in the right direction.

I usually avoid _ArrayDelete because of the slow redim, but it's probably not noticable compared to the time it takes to load a process. A non-redim workaround will be faster though.

Local $aRunning[11] = [10] ;1 based array to keep track of currently running processes
Local $aQueue[101] = [100] ;1 based array with the run path of queue'd processes, where $aQueue is the amount of processes in the queue.

While $aRunning[0] ;$aRunning will be 0 once the queue is empty and all processes have finished running.
    For $i = UBound($aRunning)-1 To 1 ;counting down because I use arraydelete and I don't want an array error.
        If ProcessExists($aRunning[$i]) Then ContinueLoop ;continue if the process is still running.
        If $aQueue[0] = 0 Then ;if a process has ended and the queue is empty
            $aRunning[0] = _ArrayDelete($aRunning,$i) ;delete a spot in the list of running processes
        Else ;if a process has ended and there are still processes queue'd
            $aRunning[$i] = Run($aQueue[1]) ;run a new process and store it's ID
            $aQueue[0] = _ArrayDelete($aQueue,1) ;delete that process from the queue

Edit: added a sleep to the loop to reduce cpu usage.

Edited by Tvern

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...