×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

What is all this flock stuff then?

What is all this flock stuff then?

What is all this flock stuff then?

(OP)
I am trying to write a form to file that is going to have a heavy load and I think I need to use flock to prevent the file being written to while operations are carried out on it.  I have this code from the o'reilly book:

$LOCK_SH = 1;
$LOCK_SH = 2;
$LOCK_SH = 4;
$LOCK_SH = 8;

sub lock{
    flock MBOX, $LOCK_EX;
    seek MBOX, 0, 2;
}

sub unlock{
    flock MBOX, $LOCK_UN;
}

open MBOX, ">>/usr/spool/mail/$env{'USER'}" or die "Can't open mailbox: $!";

lock()
print MBOX $msg, "\n\n";
unlock();

But I don't know what any of the bit's do.  Could someone explain this to me?  Also, I need to apply a lock to my own specified file, rather than a mailbox.

Thanks
Will

fortytwo
will@hellacool.co.uk
my test site

RE: What is all this flock stuff then?

flock $my_file, $locking_mode

will lock your own file for you - assuming that the variable $my_file contains the right filename and the variable $locking_mode holds the right value.

the seek business positions the filepointer to the end of the file.

If it's really busy - use a database - flock is a pain and not very portable.

Mike
michael.j.lacey@ntlworld.com
Cargill's Corporate Web Site

RE: What is all this flock stuff then?

(OP)
Got any more information on the possible values of flock (and what they do)?

Thanks
Will Jessop

fortytwo
will@hellacool.co.uk
my test site

RE: What is all this flock stuff then?

Will,

Try perldoc perlfunc and then search for flock, keep on skipping to the next occurrence of flock until you reach the function definition. There's quite a bit of info there.

Shout up if it's all greek to you.

Mike
michael.j.lacey@ntlworld.com
Cargill's Corporate Web Site

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close