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: mikeh@aslan.eng.mindspring.net (Mike harrelson) Subject: Re: flock/lockf under DU Date: 1998/11/15 Message-ID: <72lfsd$ua7$1@camel18.mindspring.com>#1/1 X-Deja-AN: 411954450 References: <36397876.693A0DB2@na.astro.it> <71ce9q$opb$1@nntpd.lkg.dec.com> Organization: MindSpring Enterprises, Atlanta Newsgroups: comp.unix.osf.osf1 In article <71ce9q$opb$1@nntpd.lkg.dec.com>, Eric Werme - replace nospam with werme <> wrote: >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. Its a pity flock(2) locks aren't recognized by fcntl()/lockf() locks, even if just locally. The ability to use local locks on files on NFS but not have them tying up lockd/portmapper can be useful. >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. That is unfortunate for systems that use NFS but only need local file locks. Our environment uses many files with locks on NFS, but are only accessed from one machine. When we used fcntl locking, both portmapper and lockd used enormous amounts of CPU. Once we switched to flock, everything still worked, but without all of the NFS file lock traffic and load by portmapper and lockd. >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. Agreed. >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. > -- mikeh