Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > file locking : does the os do this ?

Reply
Thread Tools

file locking : does the os do this ?

 
 
Jazeker
Guest
Posts: n/a
 
      03-05-2005
Hello,

This question may be a bit out of scope. Just let me know.

I have some Perl/CGI scripts that write to/read from a text file. 'till
now, I always assumed that when you open a file for writing, the OS will
not allow another instance of the script to do the same (via refusing or
making it wait, ...) and that the Perl programmer should not be
concerned with that. I have seen that Perl offers locking mechanisms,
but I usually see them in the context of random I/O file handling (and
IIRC in binary mode).

Am I wrong and do I have to include file locking in my script when using
the usual simple text file handling like :
open (TEST, "> test.txt") || die "Error opening test.txt";
print TEST "hello";
close TEST || die "Error opening test.txt";

Sorry for the somewhat off-topicness of this message... just a link to
a better newsgroup or a good read will suffice then

thx
--
print <<EOF;
Just a noobish Perl hacker
EOF
 
Reply With Quote
 
 
 
 
Chris Mattern
Guest
Posts: n/a
 
      03-05-2005
Jazeker wrote:

> Hello,
>
> This question may be a bit out of scope. Just let me know.
>
> I have some Perl/CGI scripts that write to/read from a text file. 'till
> now, I always assumed that when you open a file for writing, the OS will
> not allow another instance of the script to do the same (via refusing or
> making it wait, ...)


Depends on the OS and file system, but generally, no, the OS will assume
you know what you're doing and allow the simultaneous access.

> and that the Perl programmer should not be
> concerned with that. I have seen that Perl offers locking mechanisms,
> but I usually see them in the context of random I/O file handling (and
> IIRC in binary mode).
>
> Am I wrong and do I have to include file locking in my script when using
> the usual simple text file handling like :
> open (TEST, "> test.txt") || die "Error opening test.txt";
> print TEST "hello";
> close TEST || die "Error opening test.txt";


It depends on whether you expect other scripts or programs to be using
test.txt. If you *are* expecting this, you'll need to use flock.
>
> Sorry for the somewhat off-topicness of this message... just a link to
> a better newsgroup or a good read will suffice then
>
> thx


--
Christopher Mattern

"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Locking locking resolution Frontpage raiderhawk General Computer Support 0 01-08-2008 01:42 AM
increase in cpu usage on locking and locking the system sowmya.rangineni@gmail.com Computer Support 0 06-15-2007 12:06 PM
Application locking to support optimisitc locking ? Timasmith Java 4 11-01-2006 12:42 AM
Designer locking mdb file... (file and dir GRANTS FULL CONTROL FOR "EVERYONE") Praveen ASP .Net 1 04-16-2005 06:01 AM
Confused about locking a file via file.flock(File::LOCK_EX) Ludwigi Beethoven Ruby 5 07-26-2003 03:26 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57