[lug] Lock files....

Ian S. Nelson nelson_ at attglobal.net
Wed Apr 19 17:32:01 MDT 2000


It's for mutual exclusion semaphores.

In most OSes, semaphores are filesystem objects that are kind of secret.  When
you make an NT semaphore, an entry is created in the filesystem that you cannot
see.  Linux provides a slightly more bare metal method and you get lock files.
Semaphores are supposed to be system wide objects, so to do that you either
need some kind of shared memory or you need to create the object in part of the
OS that remains persistent, ie the filesystem.
So I have a special chunk of code that can only be run by one process at any
given time, I do this:


        open the lock file in exclusive mode (O_EXCL flag, I think)
                do the special code
        close the lock file

in both processes and then they can't both run it at the same time.  Using
files has another benefit, the kernel keeps track of filehandles and if one of
the processes die in the middle then the kernel will reclaim the handle and let
the other process run.   In theory you could use them for semaphores too, by
writing a number in to the file, but I think that is kind of messy and it
starts to call for shared memory.

I think netscape uses it to keep different processes from stomping on your
bookmarks or mail.

Ian


Grissom wrote:

> Good question.  I am wondering the same.  I keep finding a lock file in my
> $HOME/.netscape directory whenever I open more than one window of
> Netscape.  Whats that all about?
>
> ~~Brad
>
> On Wed, 19 Apr 2000, John Starkey wrote:
>
> > Could someone explain what a lock file is. I looked for it in RH Unleashed
> > and read the man pages (which seem to be somewhat cryptic:}).
> >
> > I've seen them several times. One in minicom which is /var/lock.
> >
> > But right now I am having a lot of trouble setting up my fiance's Lexmark
> > 1100. When I send the first whatever.txt > /dev/lp0 I hear the print head
> > positioning and that's all I get. There is a lock file in
> > /var/spool/lpd/lp I'm wondering if (by nature of the word "lock") this is
> > hindering further progress.
> >
> > Thanks,
> >
> > John
> >
> >
> > _______________________________________________
> > Web Page:  http://lug.boulder.co.us
> > Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug
> >
>
> _______________________________________________
> Web Page:  http://lug.boulder.co.us
> Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug






More information about the LUG mailing list