[comp.unix.ultrix] file and record locking questions

streib@silver.ucs.indiana.edu (Allan Streib) (03/29/91)

Just a couple of general questions on file and record locking under
UNIX:

(These questions are all based on my study of Ultrix 4.2 man pages)

- flock (2) and lockf (3) can be used to control concurrent access to
files, allowing cooperating processes to perform consistent operations
on files.  I understand that these system calls are advisory, and do
not (apparently) lock the file to non-cooperating processes.

- I can apparently use fcntl (2) with commands FGETLK, FSETLK, and
FSETLKW to facilitate concurrent file acccess. 

These commands are not mentioned in Rochkind's _Advanced UNIX
Programming_ text.  Are these Ultrix enhancements, or are these
portable?

Thanks for any insight. 

-Allan (streib@silver.ucs.indiana.edu)

royle@tope.cs.indiana.edu (Keenan Royle) (03/30/91)

To the best of my knowledge:

yes it is portable. (not just Ultrix)

flock locks a file.
lockf and fcntl can lock records in files (or the whole file).
lockf is just a nice front-end to fcntl.

All locks are advisory.

Ultrix is BSD based.  Portablity to system 5 may be trickier.

I can't remember the name of the sys5 routine (if it is different)
But I have used it.

In article <1991Mar29.040736.18783@bronze.ucs.indiana.edu> streib@silver.ucs.indiana.edu (Allan Streib) writes:
>Just a couple of general questions on file and record locking under
>UNIX:
>
>(These questions are all based on my study of Ultrix 4.2 man pages)
>
>- flock (2) and lockf (3) can be used to control concurrent access to
>files, allowing cooperating processes to perform consistent operations
>on files.  I understand that these system calls are advisory, and do
>not (apparently) lock the file to non-cooperating processes.
>
>- I can apparently use fcntl (2) with commands FGETLK, FSETLK, and
>FSETLKW to facilitate concurrent file acccess. 
>
>These commands are not mentioned in Rochkind's _Advanced UNIX
>Programming_ text.  Are these Ultrix enhancements, or are these
>portable?
>
>Thanks for any insight. 
>
>-Allan (streib@silver.ucs.indiana.edu)
>
>


-- 

Keenan Royle
royle@cs.indiana.edu                         	postmaster@cs.indiana.edu
royle@iubacs.bitnet

dkeisen@Gang-of-Four.Stanford.EDU (Dave Eisen) (03/30/91)

In article <1991Mar29.124756.18856@news.cs.indiana.edu> royle@tope.cs.indiana.edu (Keenan Royle) writes:
>yes it is portable. (not just Ultrix)
>
>flock locks a file.
>lockf and fcntl can lock records in files (or the whole file).
>lockf is just a nice front-end to fcntl.
>
>All locks are advisory.
>
>Ultrix is BSD based.  Portablity to system 5 may be trickier.
>

Yes it might be. The locking mechanisms (using lockf and fcntl) in 
SCO Xenix are *not* advisory locks, they are out and out LOCKS. I believe
it's the same in System V.

 

--
Dave Eisen                      
1101 San Antonio Rd. Suite 102    
Mountain View, CA 94043                   
(415) 967-5644                   dkeisen@Gang-of-Four.Stanford.EDU (for now)