Exclusive lock of a file

Discussion in 'Ruby' started by Sea&Gull, Jan 11, 2005.

  1. Sea&Gull

    Sea&Gull Guest

    Hi!

    Could you please give me a hint how in Ruby
    to open a file with exclusive lock?

    As I know, in perl it is something like this:

    open F, "filename";
    flock F, 2



    Thanks a lot!

    --
    s&g
    Sea&Gull, Jan 11, 2005
    #1
    1. Advertising

  2. Sea&Gull

    Bill Atkins Guest

    File.open "filename" do |f|
    f.flock LOCK_EX
    ...
    end

    On Wed, 12 Jan 2005 00:11:19 +0900, Sea&Gull <> wrote:
    > Hi!
    >
    > Could you please give me a hint how in Ruby
    > to open a file with exclusive lock?
    >
    > As I know, in perl it is something like this:
    >
    > open F, "filename";
    > flock F, 2
    >
    > Thanks a lot!
    >
    > --
    > s&g
    >
    >



    --
    $stdout.sync = true
    "Just another Ruby hacker.".each_byte do |b|
    ('a'..'z').step do|c|print c+"\b";sleep 0.007 end;print b.chr
    end; print "\n"
    Bill Atkins, Jan 11, 2005
    #2
    1. Advertising

  3. Sea&Gull

    Bill Atkins Guest

    Actually, that should be File::LOCK_EX.


    On Tue, 11 Jan 2005 10:19:57 -0500, Bill Atkins <> wrote:
    > File.open "filename" do |f|
    > f.flock LOCK_EX
    > ...
    > end
    >
    > On Wed, 12 Jan 2005 00:11:19 +0900, Sea&Gull <> wrote:
    > > Hi!
    > >
    > > Could you please give me a hint how in Ruby
    > > to open a file with exclusive lock?
    > >
    > > As I know, in perl it is something like this:
    > >
    > > open F, "filename";
    > > flock F, 2
    > >
    > > Thanks a lot!
    > >
    > > --
    > > s&g
    > >
    > >

    >
    >
    > --
    > $stdout.sync = true
    > "Just another Ruby hacker.".each_byte do |b|
    > ('a'..'z').step do|c|print c+"\b";sleep 0.007 end;print b.chr
    > end; print "\n"
    >



    --
    $stdout.sync = true
    "Just another Ruby hacker.".each_byte do |b|
    ('a'..'z').step do|c|print c+"\b";sleep 0.007 end;print b.chr
    end; print "\n"
    Bill Atkins, Jan 11, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bruintje Beer

    Exclusive file lock

    Bruintje Beer, Dec 21, 2007, in forum: Java
    Replies:
    6
    Views:
    490
  2. Steven D'Aprano
    Replies:
    3
    Views:
    1,836
    Jeffrey Straszheim
    Dec 6, 2008
  3. Eugene Perederey

    Setting an exclusive lock on a file

    Eugene Perederey, Mar 29, 2009, in forum: Python
    Replies:
    2
    Views:
    272
    Diez B. Roggisch
    Mar 29, 2009
  4. Replies:
    0
    Views:
    91
  5. lokesh mavale
    Replies:
    1
    Views:
    76
Loading...

Share This Page