Note: this use case is available since FLOM version 0.5.2
FLOM is not expressly designed to lock files inside a filesystem, as listed in [Similar tools] there are many alternative tools that can be used to solve the file locking issues.
If, for any reason, you prefer to use FLOM instead some other tool, simple resources are not a practical way because a simple resource name can contain only alphabetic and numeric characters while a filename typically contains characters like dots, commas, slashes, underscores and so on; you could make some shell hacks like applying md5sum to filename and adding an alphabetic char in front of the exadecimal MD5 signature, but one of the purposes of FLOM is reducing shell scripting hacks in the lock playfield.
Hierarchical resources can help you because they accept any character inside the name.
tiian@mojan:/usr$ flom -r /foo/bar -- ping -c 5 localhost PING localhost (127.0.0.1) 56(84) bytes of data. 64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.047 ms 64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.042 ms 64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.039 ms 64 bytes from localhost (127.0.0.1): icmp_seq=4 ttl=64 time=0.048 ms 64 bytes from localhost (127.0.0.1): icmp_seq=5 ttl=64 time=0.049 ms --- localhost ping statistics --- 5 packets transmitted, 5 received, 0% packet loss, time 3997ms rtt min/avg/max/mdev = 0.039/0.045/0.049/0.003 ms tiian@mojan:/usr$
tiian@mojan:/usr$ flom -r /foo/bar -- ls bin games include lib lib64 local sbin share src tiian@mojan:/usr$
the second command "ping -c 5 localhost" locks the resource "/foo/bar"; the first command "ls -la" enqueues and waits the resource "/foo/bar" becomes free before starting.
The name of an hierarchical resource must comply with these restrictions:
1. hierarchical resource names must start with a slash ("/")
2. hierarchical resource names can not end with a slash ("/")
These are valid names:
These are not valid names:
Which characters you use inside a hierarchical resource name is up to you, you only have to comply with slashes restrictions explained above.
Hierarchical resources support these options:
Hierarchical resources don't support this option:
As previously stated, other tools exists to manage file locks. So, why should I use FLOM instead of something else?
Persistent locks can be desiderable if you want a lock to survive an application or a system crash. Persistent locks can be a source of issues if your use case does not allow you to easily answer the question: "Is this persistent lock really necessary or is it a lock I should delete?"
Notably, some NFS versions did not safely manage the file locks.
Non persistent file locks needs file locks primitives at the filesystem level: some does support locking APIs.
FLOM allows you to manage distintc type of resources: you could choose FLOM just because you can use with files too.
This use case explains you how to use a file name as a resource name when using FLOM.
Flom available arguments are documented in man page: use man flom.
Flom [Configuration] explains how you can specify flom behavior without using command line arguments.