Raveen Kumar

Lockfile

lockfile

Installation

sudo apt install procmail

Description

man lockfile

Suppose you want to make sure that access to the file “important” is serialised, i.e., no more than one program or shell script should be allowed to access it. For simplicity’s sake, let’s suppose that it is a shell script. In this case you could solve it like this:

...
lockfile important.lock
...
access_"important"_to_your_hearts_content
...
rm -f important.lock
...

Now if all the scripts that access “important” follow this guideline, you will be assured that at most one script will be executing between the lockfile and the rm commands.

#Lockfile #Command-Line #Linux