LOCKFILE(1) LOCKFILE(1)

NAME
lockfile - conditional semaphore-file creator

SYNOPSIS
lockfile -sleeptime | -r retries |
-l locktimeout | -s suspend | -! | -ml | -mu | filename ...

DESCRIPTION
lockfile can be used to create one or more semaphore files. If lockfile can't create all the specified files (in the specified order), it waits sleeptime (defaults to 8) seconds and retries
the last file that didn't succeed. You can specify the number of retries to do until failure is returned. If the number of retries is -1 (default, i.e., -r-1) lockfile will retry forever.

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 proc-
mail(1)).

Mailbox locks
If the permissions on the system mail spool directory allow it, or if lockfile is suitably setgid, it will be able to lock and unlock your system mailbox by using the options -ml and -mu
respectively.

EXAMPLES
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.

ENVIRONMENT
LOGNAME used as a hint to determine the invoker's loginname

FILES
/etc/passwd to verify and/or correct the invoker's 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

SEE ALSO
rm(1), mail(1), sendmail(8), procmail(1)

DIAGNOSTICS
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.

BUGS
Definitely less than one.

WARNINGS
The behavior of the -! flag, while useful, is not necessarily intuitive or consistent. When testing lockfile's return value, shell script writers should consider carefully whether they
want to use the -! flag, simply reverse the test, or do a switch on the exact exitcode. In general, the -! flag should only be used when lockfile is the conditional of a loop.

MISCELLANEOUS
Lockfile is NFS-resistant and eight-bit clean.

NOTES
Calling up lockfile with the -h or -? options will cause it to display a command-line help page. Calling it up with the -v option will cause it to display its version information.

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 al-
ready existing file is by taking the prefix `lock.' and appending the i-node number of the file which is to be locked.

SOURCE
This program is part of the procmail mail-processing-package (v3.22) available at http://www.procmail.org/ or ftp.procmail.org in pub/procmail/.

MAILINGLIST
There exists a mailinglist for questions relating to any program in the procmail package:
<procmail-users@procmail.org>
for submitting questions/answers.
<procmail-users-request@procmail.org>
for subscription requests.

If you would like to stay informed about new versions and official patches send a subscription request to
procmail-announce-request@procmail.org
(this is a readonly list).

AUTHORS
Stephen R. van den Berg
<srb@cuci.nl>
Philip A. Guenther
<guenther@sendmail.com>

BuGless 2001/06/23 LOCKFILE(1)

lockfile - conditional semaphore-file creator的更多相关文章

  1. linux 命令中英文对照,收集

    linux 命令中英文对照,收集   linux 命令英文全文 Is Linux CLI case-sensitive? The answer is, yes. If you try to run L ...

  2. word20161209

    failback / 故障回复 failback policy / 故障回复策略 failed / 失败 failover / 故障转移 failover policy / 故障转移策略 failov ...

  3. Automake

    Automake是用来根据Makefile.am生成Makefile.in的工具 标准Makefile目标 'make all' Build programs, libraries, document ...

  4. java_log_02

    配置 在第一部分,我们将介绍配置 logback 的各种方法,给出了很多配置脚本例子.在第二部分,我们将介绍 Joran,它是一个通用配置框架,你可以在自己的项目里使用 Joran 一.Logback ...

  5. C#多线程处理

    创建多线程,并带参数! using System; using System.Collections; using System.Collections.Generic; using System.I ...

  6. How to Create a First Shell Script

    How to Create a First Shell Script   Shell scripts are short programs that are written in a shell pr ...

  7. logback配置详解

    本文转自:https://segmentfault.com/a/1190000008315137 概览 简单地说,Logback 是一个 Java 领域的日志框架.它被认为是 Log4J 的继承人.L ...

  8. HDFS Lease Recovey 和 Block Recovery

    这篇分析一下Lease Recovery 和 Block Recovery hdfs支持hflush后,需要保证hflush的数据被读到,datanode重启不能简单的丢弃文件的最后一个block,而 ...

  9. Logback中文文档(三):配置

    在第一部分,我们将介绍配置 logback 的各种方法,给出了很多配置脚本例子.在第二部分,我们将介绍 Joran,它是一个通用配置框架,你可以在自己的项目里使用 Joran. Logback里的配置 ...

随机推荐

  1. JDBC 学习笔记(三)—— JDBC 常用接口和类,JDBC 编程步骤

    1. JDBC 常用接口和类 DriverManager 负责管理 JDBC 驱动的服务类,程序中主要的功能是获取连接数据库的 Connection 对象. Connection 代表一个数据库连接对 ...

  2. gcd-模板+最小公倍数

    #include<iostream> #include<cstdio> #include<algorithm> using namespace std; int G ...

  3. [转] Makefile 基础 (4) —— Makefile 书写命令

    该篇文章为转载,是对原作者系列文章的总汇加上标注. 支持原创,请移步陈浩大神博客:(最原始版本) http://blog.csdn.net/haoel/article/details/2886 我转自 ...

  4. 小程序语音红包开发中 汉字转拼音的问题 微信小程序红包开发遇到的坑

    公司最近在开发微信小程序的红包功能,语音红包需要用到文字转拼音的功能. 之前介绍过怎么将中文的汉字转为拼音的,具体看下面这篇文章. 微信语音红包小程序开发如何提高精准度 红包小程序语音识别精准度 微信 ...

  5. Mysql之Handler_read%

    纯属自己理解,如有误导概不负责O(∩_∩)O 加索引: mysql> flush status; Query OK, rows affected (0.00 sec) mysql> flu ...

  6. JS函数(自调函数)与闭包【高级函数】

    JavaScript:BOM(浏览器对象)+DOM(文档对象)+ECMAScript javascript面向对象: * 概述: * 发展: * 互联网发展对浏览器页面性能或效果要求越来越高,HTML ...

  7. 怎样更改SQL Server 2008的身份验证方式(转)

    原文转自 http://blog.csdn.net/zjx86320/article/details/9745669         大家都知道sql server 有两种登录验证方式,即sql se ...

  8. 微信小程序 本地缓存保持登录状态之wx.setStorageSync()使用技巧

    微信小程序提供了一个如同浏览器cookie本地缓存方法,那就是今天要说的wx.setStorageSync() 注意,该方法是同步请求,还有个异步请求的方法是wx.setStorage(),参考官方文 ...

  9. 2013 ACM/ICPC 亚洲区 杭州站

    题目链接  2013杭州区域赛 Problem A Problem B 这题我用的是SPFA+ mask dp 首先跑5次SPFA: 1次是求出每个起点和其他所有点的最短距离 4次是求出每个输入的点和 ...

  10. luogu P1310 表达式的值

    题目描述 对于1 位二进制变量定义两种运算: 运算的优先级是: 先计算括号内的,再计算括号外的. “× ”运算优先于“⊕”运算,即计算表达式时,先计算× 运算,再计算⊕运算.例如:计算表达式A⊕B × ...