SPUG: Does tie() do file-locking?
bxs at sdc.cs.boeing.com
Wed Jun 14 12:29:29 CDT 2000
An OS viewpoint:
File locking is performed by OS via special system call. In typical UNIX
this feature is voluntary -- that is if a file is requested to be locked
by process A then another process B that wishes to access same file must
enquire about the file lock state and optionally wait or abort if set, such
as 'fd = open("lockfile", O_RDONLY | O_NDELAY);'.
Some UNIX systems employ madatory file locking such that process B (as above)
need not doing anything special when accessing a locked file -- it simply waits
unless it is coded to do otherwise.
Typically a file is first opened and then a system call is made to perform
the file lock; such as 'if (fcntl(fd, F_SETLK, &lock) == -1)' for example.
Files can be locked in their entirety or for a particular byte range.
I strongly suspect that file locking features aren't consistent in their
operations across machine platforms -- something to be aware of at least.
File locking has it's dangers. Especially so if OS doesn't clean up after
mis-behaving programs and/or system interruptions. Other symptoms more
difficult to diagnose occur when a process seemingly hangs waiting on
something -- a file lock to release or expire, or what? This is a tough
one to figure without good debugging tools available for reviewing process
states and their memory contents etc.
Hope that helps some from an OS viewpoint.
Hey, keep your students noses to the grind stone -- I was hoping to attend
but somehow got distracted by other things. I understand you do have some
fine Boeing folks in your class, right?
Regards... Barry Sharp
> X-Authentication-Warning: happyfunball.pm.org: mjordomo set sender to
owner-spug-list at pm.org using -f
> Date: Wed, 14 Jun 2000 09:49:28 -0700
> From: Tim Maher/CONSULTIX <tim at consultix-inc.com>
> To: spug-list at pm.org
> Subject: SPUG: Does tie() do file-locking?
> I'm teaching my "Intermediate Perl" class this week, and some questions
> about file-locking have arisen. I could probably find the answers myself by
> reading some source code, but I'd rather spend my time helping my students
> on their lab assignments instead, so I thought I'd ask if anybody knows
> the answers:
> 1) Does the -i invocation option lock the files it processes?
> (Seems like it should, but if it does, that's not documented!)
> 2) Does tie() do file-locking on its own? If not, how do
> programmers protect the tied-file from disruptive accesses?
> (such as that of a daemon program, or 500 "nobody UIDs" accessing
> the same CGI program?)
> 3) When does the file tied to a hash get updated? Immediately
> on changes to the hash? Not until UNIX flushes the buffer
> holding the changes (via the next sync() )? Whenever the
> writer of the *DB*_file module feels like doing it?
> (Seems to me that file-locking should ideally be done on a
> per-record basis by the *DB*_file module itself, but I'm
> not finding any relevant documentation, so please clue me in
> if you know!)
> | Dr. Tim Maher, CEO, Consultix (206) 781-UNIX/8649; ask for FAX# |
> | Email: tim at consultix-inc.com Web: http://www.consultix-inc.com |
> | CLASSES; 6/12: Int. Perl 6/15: Pat. Matching 8/14: UNIX 8/21: Shell |
> | DAMIAN CONWAY Seminars; Adv. OO Perl: 7/6, Parsing with Modules: 7/7 |
> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
> Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
> For Subscriptions, Email to majordomo at pm.org: ACTION spug-list EMAIL
> Replace ACTION by subscribe or unsubscribe, EMAIL by your Email address
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
For Subscriptions, Email to majordomo at pm.org: ACTION spug-list EMAIL
Replace ACTION by subscribe or unsubscribe, EMAIL by your Email address
More information about the spug-list