Thread View: comp.unix.programmer
9 messages
9 total messages
Started by Jon Nadelberg
Fri, 16 Nov 1990 02:31
Determining if an existant file is open
Author: Jon Nadelberg
Date: Fri, 16 Nov 1990 02:31
Date: Fri, 16 Nov 1990 02:31
35 lines
2007 bytes
2007 bytes
We have a program that while running maintains a checkpoint file. This file is named based on the users id, and is stored in a specific directory on the system. Our problem occurs when someone tries to start up another process under the same user id while the first one is running. The first concern is that the second process, upon seeing the existence of the checkpoint file created by the first process think that it needs to "warmstart" from the first file. It should not do this. Second, once the new process does this, it then re-initializes the checkpoint file thus corrupting it. Our thinking is this: if we can determine whether or not the checkpoint file is currently open by the first process, we can then make the decision as to whether or not to continue with a warmstart process, or in the case of the file still being open, not starting up a checkpoint file for subsequent processes. Is there a way to check if a file is currently open and being used by another process? Is there a way to "lock" a file so that other processes can not access it? We are kind of stuck with the implementation staying the way it is. The only thing we can do is Band-Aid it, so a redesign of the way it works is not a practical suggestion at this point. Any help would be appreciated. Thank you. -- ------------------------------------------------------------------------ - Jon Nadelberg - - aeusejvn@csunb.csun.edu - ------------------------------------------------------------------------
Re: Determining if an existant file is open
Author: 0257014-Robert White(140)
Date: Fri, 16 Nov 1990 20:09
Date: Fri, 16 Nov 1990 20:09
23 lines
1435 bytes
1435 bytes
In article <1990Nov16.023110.1305@csun.edu> aeusejvn@csunb.csun.edu (Jon Nadelberg) writes: >Is there a way to check if a file is currently open and being used by >another process? Is there a way to "lock" a file so that other processes >can not access it? The things that come immedately to mind are: Use the exclusive flag when calling open(2) -- must be done every time. Allow multiple opens and have the processes do read and write locks as approprate, being shure to always lock before read (you shouldn't need manditory locks in this case, just be consistant). If the file is locked the file is busy. fnctl(2) or ioctl(2) I dont remember which right now. Do the "put process number in lock file" thing as in uucp. Any sutble differences between these thecniques should be considered based on the exact internals of the app. And then combine as many of these as is reasonable. Hope it was some help, Rob.
Re: Determining if an existant file is open
Author: Guy Harris
Date: Mon, 19 Nov 1990 19:53
Date: Mon, 19 Nov 1990 19:53
5 lines
667 bytes
667 bytes
>Use the exclusive flag when calling open(2) -- must be done every time. You mean O_EXCL? That flag isn't an exclusive-use open flag; it's an "exclusive create" flag. It only causes an error if O_CREAT is also set and the file already exists.
Re: Determining if an existant file is open
Author: Chip Salzenberg
Date: Tue, 20 Nov 1990 18:28
Date: Tue, 20 Nov 1990 18:28
18 lines
1462 bytes
1462 bytes
According to rwhite@nusdecs.uucp (0257014-Robert White(140)):
>Do the "put process number in lock file" thing as in uucp.
This approach cannot be used reliably without either (1) having a lock
held forever by a dead process, which I find unacceptable, or (2)
using a kernel locking call, which renders the pid file redundant.
For you doubters: Once you've determined that a lock file is stale and
you want to unlink() it, how do you know the lock file hasn't been
replaced in between the decision to unlink() and the unlink() itself?
I really like kernel record locks for lots of reasons, but the primary
one is that locks disappear automatically when the locking process
dies, even if the death is abnormal (SIGKILL, core dump, anything).
--
Chip Salzenberg at Teltronics/TCT <chip@tct.uucp>, <uunet!pdn!tct!chip>
"I've been cranky ever since my comp.unix.wizards was removed
by that evil Chip Salzenberg." -- John F. Haugh II
Re: Determining if an existant file is open
Author: jon nadelberg
Date: Wed, 21 Nov 1990 06:15
Date: Wed, 21 Nov 1990 06:15
10 lines
912 bytes
912 bytes
Thanks to everyone who answered my question. We'll probably be able to get something functioning now. Much appreciated. -- ------------------------------------------------------------------------ - Jon Nadelberg - - aeusejvn@csunb.csun.edu - ------------------------------------------------------------------------
Re: Determining if an existant file is open
Author: Dan Bernstein
Date: Wed, 21 Nov 1990 19:42
Date: Wed, 21 Nov 1990 19:42
17 lines
1288 bytes
1288 bytes
In article <274975C4.21C@tct.uucp> chip@tct.uucp (Chip Salzenberg) writes: > According to rwhite@nusdecs.uucp (0257014-Robert White(140)): > >Do the "put process number in lock file" thing as in uucp. > This approach cannot be used reliably without either (1) having a lock > held forever by a dead process, which I find unacceptable, or (2) > using a kernel locking call, which renders the pid file redundant. It can be used reliably if you put information like pid and date into the name of the lock file. > For you doubters: Once you've determined that a lock file is stale and > you want to unlink() it, how do you know the lock file hasn't been > replaced in between the decision to unlink() and the unlink() itself? The old name will never be reused, so there's no danger of replacement. ---Dan
Re: Determining if an existant file is open
Author: Jack J. Woehr
Date: Thu, 22 Nov 1990 21:05
Date: Thu, 22 Nov 1990 21:05
19 lines
962 bytes
962 bytes
Grammar Police, Ma'am! Open Up!
Ahem ...
The word y'all are fseeking and not ffinding is:
extant
There *is* and English word "existence", but if "existant"
is a relative thereof, it's from the wrong side of the bedsheets.
Dank U.
--
<jax@well.{UUCP,sf.ca.us} >< Member, > /// ///\\\ \\\ ///
<well!jax@lll-winken.arpa >< X3J14 TC > /// /// \\\ \\\///
<JAX on GEnie >< for ANS > \\\ /// ///====\\\ ///\\\
<SYSOP RCFB (303) 278-0364>< Forth > \\\/// /// \\\ /// \\\
Re: Determining if an existant file is open
Author: Patrick Hertel
Date: Fri, 23 Nov 1990 18:55
Date: Fri, 23 Nov 1990 18:55
25 lines
1284 bytes
1284 bytes
In article <21795@well.sf.ca.us> jax@well.sf.ca.us (Jack J. Woehr) writes: > > Grammar Police, Ma'am! Open Up! > > Ahem ... > > The word y'all are fseeking and not ffinding is: > > extant > > There *is* and English word "existence", but if "existant" >is a relative thereof, it's from the wrong side of the bedsheets. > > Dank U. > You are only partly right since you can't use extant in the context of "if an extant...". Therefore the word is: existing -- Pat Hertel Canadian Meteorological Centre Analyst/Programmer 2121 N. Service Rd. % rm God phertel@cmc.aes.doe.ca Dorval,Quebec rm: God non-existent Environment Canada CANADA H9P1J3
Re: Determining if an existant file is open
Author: Derek E. Terveer
Date: Tue, 27 Nov 1990 23:22
Date: Tue, 27 Nov 1990 23:22
21 lines
1307 bytes
1307 bytes
afsipmh@cid.aes.doe.CA (Patrick Hertel) writes: > You are only partly right since you can't use extant in the context of > "if an extant...". Therefore the word is: > existing Huh? In my dictionary, "extant" is billed as an adjective. Since it is modifying the noun "file", you should be able to use it in this context. Substitute another adjective, like "huge" or "red": if a huge file is open if a red file is open if an extant file is open Same thing. derek -- Derek Terveer det@hawkmoon.MN.ORG Minnesota Field Hockey Association, North Central Section University of Minnesota Women's Lacrosse, Midwest District
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads