Re: fcntl problems



On Aug 31, 12:23 am, Miles <semantic...@xxxxxxxxx> wrote:
Sorry, that last quote-only reply was accidental. :)

On 8/30/07, mhearne808 wrote:
I've been doing some experiments, and here are some specific examples
to try.

[snipped examples]

From these last two experiments I can only conclude that file locking
isn't doing a durned thing.

What's going on?

File locking isn't doing a durned thing in those cases because you're
only obtaining the lock from a single process.

According to my Python Cookbook:
"Exclusive lock: This denies all _other_ processes both read and write
access to the file."

This is only for mandatory locking; POSIX flock is advisory locking,
which states: "Only one process may hold an exclusive lock for a given
file at a given time." Advisory locks don't have any effect on
processes that don't use locks. Mandatory locks are kernel enforced,
but non-POSIX and not available in Mac OS X.

-Miles

I think I'm still confused. Maybe I should explain the behavior that
I want, and then figure out if it is possible.

I have a script that will be run from a cron job once a minute. One
of the things this script will do is open a file to stash some
temporary results. I expect that this script will always finish its
work in less than 15 seconds, but I didn't want to depend on that.
Thus I started to look into file locking, which I had hoped I could
use in the following fashion:

Process A opens file foo
Process A locks file foo
Process A takes more than a minute to do its work
Process B wakes up
Process B determines that file foo is locked
Process B quits in disgust
Process A finishes its work

Since I couldn't figure out file locking, I decided to just have
Process A create a "pid" file in the directory - analogous to the
"Occupied" sign on an airplane bathroom. This works, but it seems a
little hacky.

--Mike

.



Relevant Pages

  • Re: Locking: kern/50827
    ... > I don't think you'll ever find anyone interested in file locking ... Hand-rolled implementations will only work with other programs which use ... There's no simple way of doing per-descriptor locks using BSD and SysV ... Essentially, implementing locks at a higher level is alway more difficult, ...
    (freebsd-hackers)
  • Re: Locking: kern/50827
    ... >> I don't think you'll ever find anyone interested in file locking ... >> at a higher level in your application. ... > 1) File locking works with any program using the file locking API. ... > 3) There's no simple way of doing per-descriptor locks using BSD and SysV ...
    (freebsd-hackers)
  • Re: Getting your own process ID
    ... > I am doing some work where I want to do locking, ... > How does the PHP script identify itself? ... use file locking. ... I serialize session requests per session ID by making a lock on the sesssion ...
    (comp.lang.php)
  • Re: PHP blocks session_start while other PHP instance is running
    ... It seems that while a PHP script is being executed (using ... CGI) and has a session open, trying to re-open the same session in ... I'll use the database if I have to, ... If it is due to file locking then the solution is quite simple - just ...
    (comp.lang.php)
  • How to check for already running program?
    ... file locking can be used for mutual ... exclusion - you should ask about this in a platform-specific newsgroup, ... is not already and instance of the designated script running. ... /* but aren't possible when run as a simple cgi script. ...
    (comp.unix.programmer)