file locking

B

Bedo Sandor

Hi All,

There are 3 different file locking mechanisms in C:

flock
lockf
fcntl

I want to write a Ruby script, which shares files with
a C program using all of these lockings.

As I can see objects with the type File have an flock
method. This is the only one I can use. There is an
fcntl method, but I don't know how to use it. What
kind of parameters can I pass to fcntl? I want to
implement this code in Ruby for fcntl:

def lock_fcntl(fd)

# struct flock f_lock;

# memset(&f_lock, '\0', sizeof(f_lock));
# f_lock.l_type = F_WRLCK;
# f_lock.l_whence = SEEK_SET;
# f_lock.l_start = 0;
# f_lock.l_len = 0;
# fcntl(fd, F_SETLKW, &f_lock);

end

and I need a lockf-type method too:

def lock_lockf(fd)
# ???
end

Could you show me how to use fcntl, and how to
access lockf from Ruby?
 
J

Josef 'Jupp' Schugt

Saluton!

* Bedo Sandor; 2003-07-15, 12:46 UTC:
There are 3 different file locking mechanisms in C:

flock
lockf
fcntl

I want to write a Ruby script, which shares files with
a C program using all of these lockings.

Maybe 'filelock' is what you are looking for (at least it works fine
when sharing mbox files with mutt).

Gis,

Josef 'Jupp' Schugt
 
B

Bermejo, Rodrigo

have you checked it 'http://raa.ruby-lang.org/list.rhtml?name=filelock'
out

-r.


Bedo said:
Hi All,

There are 3 different file locking mechanisms in C:

flock
lockf
fcntl

I want to write a Ruby script, which shares files with
a C program using all of these lockings.

As I can see objects with the type File have an flock
method. This is the only one I can use. There is an
fcntl method, but I don't know how to use it. What
kind of parameters can I pass to fcntl? I want to
implement this code in Ruby for fcntl:

def lock_fcntl(fd)

# struct flock f_lock;

# memset(&f_lock, '\0', sizeof(f_lock));
# f_lock.l_type = F_WRLCK;
# f_lock.l_whence = SEEK_SET;
# f_lock.l_start = 0;
# f_lock.l_len = 0;
# fcntl(fd, F_SETLKW, &f_lock);

end

and I need a lockf-type method too:

def lock_lockf(fd)
# ???
end

Could you show me how to use fcntl, and how to
access lockf from Ruby?

--
General Electric - CIAT
Advanced Engineering Center
________________________________________
Rodrigo Bermejo
Information Technologies.
Dial-comm : *879-0644
Phone :(+52) 442-196-0644
mailto:[email protected]
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,231
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top