Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What is all this flock stuff then? 1

Status
Not open for further replies.

fortytwo

Technical User
Apr 18, 2000
206
GB
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.&nbsp;&nbsp;I have this code from the o'reilly book:<br><FONT FACE=monospace><br>$LOCK_SH = 1;<br>$LOCK_SH = 2;<br>$LOCK_SH = 4;<br>$LOCK_SH = 8;<br><br>sub lock{<br>&nbsp;&nbsp;&nbsp;&nbsp;flock MBOX, $LOCK_EX;<br>&nbsp;&nbsp;&nbsp;&nbsp;seek MBOX, 0, 2;<br>}<br><br>sub unlock{<br>&nbsp;&nbsp;&nbsp;&nbsp;flock MBOX, $LOCK_UN;<br>}<br><br>open MBOX, &quot;&gt;&gt;/usr/spool/mail/$env{'USER'}&quot; or die &quot;Can't open mailbox: $!&quot;;<br><br>lock()<br>print MBOX $msg, &quot;\n\n&quot;;<br>unlock();<br></font><br>But I don't know what any of the bit's do.&nbsp;&nbsp;Could someone explain this to me?&nbsp;&nbsp;Also, I need to apply a lock to my own specified file, rather than a mailbox.<br><br>Thanks<br>Will <p>fortytwo<br><a href=mailto:will@hellacool.co.uk>will@hellacool.co.uk</a><br><a href= test site</a><br>
 
flock $my_file, $locking_mode<br><br>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.<br><br>the seek business positions the filepointer to the end of the file.<br><br>If it's really busy - use a database - flock is a pain and not very portable. <p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
Got any more information on the possible values of flock (and what they do)?<br><br>Thanks<br>Will Jessop <p>fortytwo<br><a href=mailto:will@hellacool.co.uk>will@hellacool.co.uk</a><br><a href= test site</a><br>
 
not in work for the next couple of days - back in thursday - will look then if you still need help - sorry <p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
Will,<br><br>You still need help with this?<br><br>Mike<br> <p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
Will,<br><br>Try <FONT FACE=monospace><b>perldoc perlfunc</font></b> and then search for <FONT FACE=monospace><b>flock</font></b>, keep on skipping to the next occurrence of <FONT FACE=monospace><b>flock</font></b> until you reach the function definition. There's quite a bit of info there. <br><br>Shout up if it's all greek to you. <p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top