partial file locking with ndbm(3) files

partial file locking with ndbm(3) files

Post by Steve Be » Wed, 02 May 1990 22:28:00

  I'm trying to write a database application (a small one) which
uses ndbm(3).  I'd like to find out how I could write my application
so that a minimum portion of the database is locked at any one
time.  Naturally, the ndbm man page skirts the whole issue of record
locking (What is a concurrent update anyway? :-)

  The most common operations on the database will be (in this order):

   search every record for some trait or another.
   update a single record.
   add a single record.

  I'd rather not lock the whole database when I do a 'search' since
that might hold up the updates&adds for an inordinate amount of time.
While I can readily see how to accomplish a whole-database locking
scheme, I think my performance would be substantially better with
single-record locking.

                                - Steve Benz


1. ndbm and file locking

I have an ndbm database which could be accessed by more than one
process at a time.  So, of course I want to do file locking.

So I have a few questions which should be vendor independent (I hope).

lockf wants a file descriptor for the first argument, not a pointer to


1) Should I open the .pag file RDWR, do a lock on it, and then in
   the same process, do the dbm_open, dbm_store, dbm_close?

2) I would think I'll have to lock the entire file, as that fd isn't
   going to know what offset in the file will point to where
   I am about to write in the .pag file.  Must I lock the entire

As I said, this would seem to be vendor independent, but I'll mention
that I am running Solaris 2.3+patches on a Sparc 20.

Thanks in advance for any ideas/suggestions/comments.

Rob Francis
Paradigm Systems   <URL:>

2. SSHFS, NFS, ... : what's the best? what else is there?


4. transfer partial lines of a file to new file

5. Does FreeBSD support more than 2 IDE Controllers?

6. Locking a file temporarily (till the file is transferred completely).

7. DNS setup problem for Linux Red Hat 7.1

8. Exclusive Unix file system file write locks and Oracle and Veritas

9. File locking text file in linux using C

10. Solaris 2.5 system file table and file lock info for alerting on thresholds

11. mail problem: file permissions for lock file

12. Locking Files with FILE pointers