How to use flock on Linux

Viewed 5086
1 Answers

The 'flock' is the most useful then operates with a file descriptor. You should also provide a command to execute if locking on on file/dir-name. I guess, internally it works as the following:

    exec 4<$name # open
    flock 4
    <your_command_here>
    exec 4<&-    # close

In your example you can replace locks with

    flock $temp_dir sleep 5s

to check the difference.

Related