2

I have two scripts let's call them script1 and script2.

The script1 is scheduled every 2 minutes and it takes 4 minutes to execute the script2 is scheduled every 30 minutes and it takes 4 minutes to execute. At the moment I'm using flock within the scripts to assure that script1 and script2 never run concurrently. However the exclusiveness of the write lock cause the script1 to never be executed concurrently as well.

In my case I would like to allow parallelism of script1 and non concurrency with script2. If I use read lock between the instances of script1 the problem is that I will cause a starvation for script2 that it will never be executed.

Is there a clever way to do that?

That is once a write lock is asked the following read lock are not granted? Because this is the problem while script2 wait for a write lock there are other instances of script1 that are able to get the read lock and the script2 instance wait for ever

  • 1
    You can use two lock files: one read lock created by script1 and one write lock created by script2. When script1 starts, it first waits for lock2, and then creates lock1. When script2 starts it immediately creates lock2, then waits until script1 release lock1. – jimmij Jun 20 '16 at 22:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.