bash: run a script at most 3 times simultanously
Hi
I would like a script (let us call it simu) to run at most 3 times simultanously (to avoid overloading my server). My idea would be to write a second script which would run simu only if less then 3 simus are already running. If 3 simus are running, he should wait for another one to finish, before starting a new one. Does anyone know how I could do this? Thank you for your help Patrick |
Why not use a file to store a number and increment it following the number
of time you start your script ? |
with xinetd you can sepcify how many servers to start.
dunno about inetd. |
The problem you'll have is synchronisation. The solution has to be via some atomic operation, like a mv or a ln for example...
Yves. |
At the top of your script you could put:
Code:
check_instances() { There is a possibility for false-positives here (if the string "simu" is found elswhere in your process table) but this will dissappear if you choose a more unique name for your script. |
All times are GMT -5. The time now is 04:39 PM. |