From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,6fcf4f0da234c858 X-Google-Attributes: gidfee84,public From: nospam@zk3.dec.com (Eric Werme - replace nospam with werme) Subject: Re: flock/lockf under DU Date: 1998/10/30 Message-ID: <71ce9q$opb$1@nntpd.lkg.dec.com>#1/1 X-Deja-AN: 406697205 References: <36397876.693A0DB2@na.astro.it> Organization: Digital Equipment Corporation Reply-To: (Replace nobody with werme) nobody@zk3.dec.com Newsgroups: comp.unix.osf.osf1 Massimo Gais writes: >I'd like to now what's the best function to call under DU (4.0) >between flock() and lockf(); I tell everyone to use fcntl() as I can never remember what the others do. Lessee... >From lockf(3) The lockf() function locks and unlocks sections of an open file. Unlike the fcntl() function, however, its interface is limited to setting only write (exclusive) locks. Although the lockf() and fcntl() functions are different, the implementa- tions are fully integrated. Therefore, locks obtained from one function are honored and enforced by the other lock function. So, flock(2) _in currently shipping code_ is separate: The flock() interface is not part of any UNIX standard. Therefore, if you are designing and writing applications to be portable across platforms, DIGITAL recommends that you use the fcntl() file locking interface instead of flock(). Internally, flock does VFS-level locking, i.e., the real file system is not told of what's happening. This makes flock useleess on NFS files if multiple systems are involved. _However_, in the next major release, the flock interface will call the fcntl-style locking routines and _will_ work over NFS. Still, please use fcntl.... BTW, lockf(3) is a libc routine that calls fcntl(2). >I have to fopen() the mail spoolfile for reading, but if I >another process has already locked with flock() the fopen() >simple doesn't care... Both locking styles are "advisory locking" Mandatory locking is available on local file systems. See chmod(2). I am in the camp that says mandatory locking is the work of the devil. Don't use it. Trying to make this work over NFS would result in massive confusion because someone on a NFS client could lock a file on the server. Either lock state would have to be preserved over reboots or reboots could only be done when the client releases the lock. >I was thinking this way because DU should be a BSD-derivative Unix, >so it should at first use flock(), not lockf(). Solaris supports flock(), but does fcntl-style locking. flock(2) was written before BSD shipped NFS. OSF/1 came with the Univ. of Guelph NFS, but we replaced that with Sun's ONC NFS. OSF put in a lot of SysVisms. I'd recommend you stick to Posix calls whereever possible. -- <> Eric (Ric) Werme <> The above is unlikely to contain <> <> ROT-13 addresses: <> official claims or policies of <> <> <> Compaq Computer Corp. <> <> <> http://www.cyberportal.net/werme <>