URN Logo
UNIX Resources » Linux » China Linux Forum » Perl 编 程 » 3 » windows 2000下文件加锁的问题 file flock
announcement 声明: 本页内容为中国Linux论坛的内容镜像,文章的版权以及其他所有的相关权利属于中国Linux论坛和相应文章的作者,如果转载,请注明文章来源及相关版权信息。
Resources
China Linux Forum(finished)
Linux Forum(finished)
FreeBSD China(finished)
linuxforum.net
  业界新闻与评论
  自由软件杂谈
  IT 人生
  Linux软件快递
  翻译作坊
  Linux图书与评论
  GNU Emacs/XEmacs
  Linux 中文环境和中文化
  Linux桌面与办公软件
  Linux 多媒体与娱乐版
  自由之窗Mozilla
  笔记本电脑上的Linux
  Gentoo
  Debian 一族
  网络管理技术
  Linux 安装与入门
  WEB服务器和FTP服务器
  域名服务器和邮件服务器
  Linux防火墙和代理服务器应用
  文件及打印服务器
  技术培训与认证
  Linux内核技术
  Linux 嵌入技术
  Linux设备驱动程序
  Linux 集群技术
  LINUX平台数据库
  系统和网络安全
  CPU 与 编译器
  系统计算研究所专栏
  Linux下的GUI软件开发
  C/C++编程版
  PHP 技 术
  Java&jsp技术
  Shell编程技术
  Perl 编 程
  Python 编 程
  XML/Web Service 技术
  永远的Unix
  FreeBSD世界
   
windows 2000下文件加锁的问题 file flock
windows 2000下文件加锁的问题 file flock - wiwj [2005-01-14 17:03 | 529 byte(s)]
 
 
Re: windows 2000下文件加锁的问题 file flock - wiwj [2005-01-17 16:20 | 1,701 byte(s)]
 
Subject: windows 2000下文件加锁的问题 file flock
Author: wiwj    Posted: 2005-01-14 17:03    Length: 529 byte(s)
[Original] [Print] [Top]
有一程序A会不停的更新一些文件(简称原文件)。

我用 perl 了个小程序,读“原文件”,并做些处理,
将结果另存为新文件。

现在会出现这样的情况:
perl程序在读取“原文件”时,程序A会同时更新这些文件,
结果我读到的内容就不完整(只有前面一部分)。

我现在试图在perl中用flock在读“原文件”之前现加个锁。

问题是:
我不知道这会不会影响程序A对“原文件”的写?
还是操作系统会自动挂起A,直到我unlock,然后正常写入?
[Original] [Print] [Top]
Subject: Re: windows 2000下文件加锁的问题 file flock
Author: wiwj    Posted: 2005-01-17 16:20    Length: 1,701 byte(s)
[Original] [Print] [Top]
网上查了下,我的问题好像不能用flock解决。
因为flock是“非强制的”,只有当2个程序都使用flock才行。我无法修改程序A。
暂时用其他的方法解决文件完整性的问题。

下面是一些关于的flock的说明:(第五条我看了半天,才看明白,乱翻一下)
Note that flock() locks are advisory, so it won't affect your other
script unless that also uses flock. The rules governing locks are:

1. Locks don't affect anything except other locks: they don't stop
anyone opening, reading, writing, deleting, etc. the file.


2. You can only hold a lock on an open file. (The details of what
happens when you have several handles open on the same file depend
on the underlying system: don't go there.


3. If someone holds a LOCK_EX lock, all attempts to get a lock will
fail. (LOCK_EX means 'exclusive lock'.)


4. If someone holds a LOCK_SH lock, attempts to get a LOCK_EX lock
will fail but attempts to get another LOCK_SH lock will
succeed. (LOCK_SH means 'shared lock'.)


5. If you can't get the lock you are trying for, then if you specify
LOCK_NB (use | rather than +, i.e. 'flock $FH, LOCK_SH | LOCK_NB)
the flock call will fail, and if you don't flock will just not
return until you can.
5. 当你试图得到一个文件的“锁”,又无法得到时,
如果你指定了 LOCK_NB,那么flock将立即返回fail,
如果你没有指定 LOCK_NB,flock直到你得到锁,才返回。
[Original] [Print] [Top]
Subject: Re: windows 2000下文件加锁的问题 file flock
Author: Qiang    Posted: 2005-01-19 12:13    Length: 47 byte(s)
[Original] [Print] [Top]
试试先把你要处理的文件复制一个, 处理这个复制的.
----
$PerlMonger{Toronto}=>Qiang
[Original] [Print] [Top]
« Previous thread
新手问一个字符处理的问题
Perl 编 程
3
Next thread »
wiki.perlchina.org
     

Copyright © 2007 UNIX Resources Network, All Rights Reserved.      About URN | Privacy & Legal | Help | Contact us
备案序号: 京ICP备05006143    webmaster: webmaster@unixresources.net
This page created on 2008-07-17 04:08:56, cost 0.057960033416748 ms.