* flock/lockf under DU
@ 1998-10-30 5:00 Massimo Gais
1998-10-30 5:00 ` Eric Werme - replace nospam with werme
0 siblings, 1 reply; 3+ messages in thread
From: Massimo Gais @ 1998-10-30 5:00 UTC (permalink / raw)
Hello,
I'd like to now what's the best function to call under DU (4.0)
between flock() and lockf();
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...
I was thinking this way because DU should be a BSD-derivative Unix,
so it should at first use flock(), not lockf().
Any explaination about this argument is very welcome.
TIA,
Massimo Gais <mgais@na.astro.it>
----
"640K ought to be enough for anybody."
-- Bill Gates, 1981
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: flock/lockf under DU 1998-10-30 5:00 flock/lockf under DU Massimo Gais @ 1998-10-30 5:00 ` Eric Werme - replace nospam with werme 1998-11-15 5:00 ` Mike harrelson 0 siblings, 1 reply; 3+ messages in thread From: Eric Werme - replace nospam with werme @ 1998-10-30 5:00 UTC (permalink / raw) Massimo Gais <mgais@na.astro.it> 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 <> <> <jrezr@mx3.qrp.pbz> <> Compaq Computer Corp. <> <> <jrezr@plorecbegny.arg> <> http://www.cyberportal.net/werme <> ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: flock/lockf under DU 1998-10-30 5:00 ` Eric Werme - replace nospam with werme @ 1998-11-15 5:00 ` Mike harrelson 0 siblings, 0 replies; 3+ messages in thread From: Mike harrelson @ 1998-11-15 5:00 UTC (permalink / raw) In article <71ce9q$opb$1@nntpd.lkg.dec.com>, Eric Werme - replace nospam with werme <> wrote: >Massimo Gais <mgais@na.astro.it> 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 ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~1998-11-15 5:00 UTC | newest] Thread overview: 3+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 1998-10-30 5:00 flock/lockf under DU Massimo Gais 1998-10-30 5:00 ` Eric Werme - replace nospam with werme 1998-11-15 5:00 ` Mike harrelson
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox