flock FILEHANDLE, OPERATION |
支持文件锁定在指定的文件句柄,使用系统的flock(),fcntl()文件锁定,或使用lockf()。确切的实现是依赖于你的系统支持。操作是此处定义的静态值之一...
Operation Result LOCK_SH Set shared lock. LOCK_EX Set exclusive lock. LOCK_UN Unlock specified file. LONG_NB Set lock without blocking.
0 设置/取消锁定失败时
1 设置/取消锁定成功时
以下是用法...
这里有一个邮箱附加器 BSD系统:
use Fcntl ':flock'; # import LOCK_* constants
sub lock {
flock(MBOX,LOCK_EX);
# and, in case someone appended
# while we were waiting...
seek(MBOX, 0, 2);
}
sub unlock {
flock(MBOX,LOCK_UN);
}
open(MBOX, ">>/usr/spool/mail/$ENV{'USER'}")
or die "Can't open mailbox: $!";
lock();
# by www.gitbook.net
print MBOX $msg,"\n\n";
unlock();