Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^4: Ensuring only one copy of a perl script is running at a time

by ikegami (Patriarch)
on Dec 19, 2006 at 18:12 UTC ( [id://590735]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Ensuring only one copy of a perl script is running at a time
in thread Ensuring only one copy of a perl script is running at a time

I find extremely rude posts that do nothing but contradict the parent when the poster could have verified that the parent was correct.

You're wrong. flock does NOT use its own advisory locking. If flock implemented some kind of advisory locking, Windows's type command would know nothing of it, yet it can't read a file locked using flock.

use Fcntl qw( :flock ); open(my $fh, '>', 'file') or die("Unable to open file: $!\n"); print $fh ("ok\n"); print("type without lock:\n"); system("type file"); print("\n"); flock($fh, LOCK_EX|LOCK_NB) or die("Unable to lock file: $!\n"); print("type with lock:\n"); system("type file"); unlink('file');

outputs

>perl 590735.pl type without lock: ok type with lock: The process cannot access the file because another process has locked +a portion of the file.

Tested with 5.6.0, 5.6.1, 5.8.0 and 5.8.8.

Update: Updated to show that type works when the file isn't locked by flock.

Replies are listed 'Best First'.
Re^5: Ensuring only one copy of a perl script is running at a time
by tye (Sage) on Dec 19, 2006 at 18:41 UTC

    It seems the point is that flock is documented to have behavior that varies between platforms. If flock is documented as always providing advisory locking, then I think that is a documentation bug (it reads to me that it certain may provide only advisory locking, but I didn't find a clear statement that manditory locking isn't the result on some platforms -- it quickly points to perlport, in fact).

    So, if flock is documented to behave differently on different platforms, then writing code that depends on flock being advisory is not portable (which it obviously isn't, in practice).

    It looks to me like you missed the point. And I don't see where any technical point was "just refuted" when it could have just been checked by Moron. But I certainly could be missing something.

    - tye        

      And I don't see where any technical point was "just refuted" when it could have just been checked by Moron.

      I was pointing out the root cause of the problem was that Windows usedmandatory locking. To this, he replied advisory locking was being used.

      It looks to me like you missed the point.

      I had no comment to make on whether flock should or shouldn't be used. I'm not sure I'd call that missing the point. I was explaining the root cause of the problem in response to someone claiming it was caused by DATA behaving differently on Windows and unix. (It doesn't.)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://590735]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2024-04-19 02:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found