Copyright © tutorialspoint.com
If the number of retries expires before all files have been created, lockfile returns failure and removes all the files it created up till that point.
Using lockfile as the condition of a loop in a shell script can be done easily by using the -! flag to invert the exit status. To prevent infinite loops, failures for any reason other than the lockfile already existing are not inverted to success but rather are still returned as failures.
All flags can be specified anywhere on the command line, they will be processed when encountered. The command line is simply parsed from left to right.
All files created by lockfile will be read-only, and therefore will have to be removed with rm -f.
If you specify a locktimeout then a lockfile will be removed by force after locktimeout seconds have passed since the lockfile was last modified/created (most likely by some other program that unexpectedly died a long time ago, and hence could not clean up any leftover lockfiles). Lockfile is clock skew immune. After a lockfile has been removed by force, a suspension of suspend seconds (defaults to 16) is taken into account, in order to prevent the inadvertent immediate removal of any newly created lockfile by another program (compare SUSPEND in procmail(1)).
... lockfile important.lock ... access_"important"_to_your_hearts_content ... rm -f important.lock ...
|LOGNAME||used as a hint to determine the invokers loginname|
|/etc/passwd||to verify and/or correct the invokers loginname (and to find out his HOME directory, if needed)|
|/var/mail/$LOGNAME.lock||lockfile for the system mailbox, the environment variables present in here will not be taken from the environment, but will be determined by looking in /etc/passwd|
|Filename too long, ...||Use shorter filenames.|
|Forced unlock denied on "x"|
|No write permission in the directory where lockfile "x" resides, or more than one lockfile trying to force a lock at exactly the same time.|
|Forcing lock on "x"||Lockfile "x" is going to be removed by force because of a timeout (compare LOCKTIMEOUT in procmail(1)).|
|Out of memory, ...||The system is out of swap space.|
|Signal received, ...||Lockfile will remove anything it created till now and terminate.|
|Sorry, ...||The retries limit has been reached.|
|Truncating "x" and retrying lock|
|"x" does not seem to be a valid filename.|
|Try praying, ...||Missing subdirectories or insufficient privileges.|
Multiple -! flags will toggle the return status.
Since flags can occur anywhere on the command line, any filename starting with a - has to be preceded by ./.
The number of retries will not be reset when any following file is being created (i.e., they are simply used up). It can, however, be reset by specifying -rnewretries after every file on the command line.
Although files with any name can be used as lockfiles, it is common practice to use the extension .lock to lock mailfolders (it is appended to the mailfolder name). In case one does not want to have to worry about too long filenames and does not have to conform to any other lockfilename convention, then an excellent way to generate a lockfilename corresponding to some already existing file is by taking the prefix lock. and appending the i-node number of the file which is to be locked.
<firstname.lastname@example.org> for submitting questions/answers.
for subscription requests.
If you would like to stay informed about new versions and official patches send a subscription request to
Copyright © tutorialspoint.com