Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!crdgw1!uunet!convex!newsadm From: tchrist@convex.COM (Tom Christiansen) Newsgroups: comp.unix.shell Subject: Re: Creating a lock file in csh? Message-ID: <1991Apr15.230427.9231@convex.com> Date: 15 Apr 91 23:04:27 GMT References: <1991Apr15.205654.26253@unhd.unh.edu> Sender: newsadm@convex.com (news access account) Reply-To: tchrist@convex.COM (Tom Christiansen) Organization: CONVEX Software Development, Richardson, TX Lines: 31 Nntp-Posting-Host: pixel.convex.com From the keyboard of al@unhd.unh.edu (Anthony Lapadula): :I'll soon be writing a script (most likely in csh) that has at least :one critical section (updating a file). I need to ensure that only :one executing copy of the script actually accesses the file at any :given time. : :I had thought that creating a lock file -- and checking for its presence :when starting up -- would be a reasonable way to solve the problem. :I can't seem to figure out how to do it (short of invoking a C program :that invokes open(2) with O_EXCL). We're trying to keep the script :machine-independent, so the open(2) solution is out. : :I looked at mktemp(1), but it also seems insufficient. : :Lastly, does it matter that we're using NFS? I would strongly counsel against using csh. Use a Bourne-compatible shell for shell programming. Yes, it makes a difference whether you're using NFS: old assumptions about idempotency of operations (like create or unlink or O_EXCL) are no longer valid; you have to go through the lockdaemon_from_hell to make these things work. Of course, not all hosts have a lockdaemon, so so much for machine-independence. You could use fcntl() so it works both w/ and w/o a lockd, but old BSD hosts don't do file-locking that way. And anyway, you can't get to fcntl() from a shell script anyway. You *can* get at these functions from perl scripts, and you still get machine-independence because you don't have to recompile. You might even use #ifdef __convex__ or whatever if you really want. --tom