A
A
Alexander Arbuzov2018-04-18 15:09:08
linux
Alexander Arbuzov, 2018-04-18 15:09:08

How to work with the flock utility?

I'm trying to figure out the flock utility in order to implement the launch of the script by cron once every few seconds,
as I understand it, when you start the command through flock, restarting should be impossible while the created loc file exists. However, my team


flock -w 10 /tmp/lock.lock ./dev.sh

Works wonderfully as many times in a row as I give this command in the console. What am I doing wrong? Or did I misunderstand what the utility does?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Artem @Jump, 2018-04-18
Tag

I'm trying to figure out the flock utility in order to implement the launch of the script by cron once every few seconds
And what does this utility have to do with cron launch?
Or did I misunderstand what the utility does?
Well, it's hard to misunderstand. All functionality of the utility is described in its name.
The task of the utility is to lock the file (FileLOCK).
Run ./dev.sh, create a lock file /tmp/lock.lock, -w 10 - time to wait for the lock file to be released.

J
jcmvbkbc, 2018-04-18
@jcmvbkbc

flock -w 10 /tmp/lock.lock ./dev.sh Works wonderfully
as many times in a row as I give this command in the console. What am I doing wrong? Or did I misunderstand what the utility does?

Misunderstood. In this form of launch, it locks the file ./dev.sh for the duration of the execution, after which it releases it. You can run it like this:
and then serialization to /tmp/lock.lock should be observed and a timeout fallback if ./dev.sh runs longer than 10 seconds.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question