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!

Keeping 2 people from updating a file at the same time.

Status
Not open for further replies.

WaltS

Programmer
Mar 11, 2002
13
US
I am attempting to set a tempoorary 'lock' file so that another user cannot update a certain file while the lock file exists.
while [file exists $file.lck]{
wait 1
}
The problem I am having is when the lck file is removed, the program does not jump out of the while loop. We use something similar in our Korn Shell scripts which works fine.
 
Your code evaluates the ' [file exists $file.lck]' condition only once: before the lock file is removed.

The while command is evaluated by Tcl as all other commands: Tcl evaluates the var references '$var' and script calls '[script]' of the command line before calling the command.
So, because the lock file is here, your while command is like:
Code:
while 1 {wait 1}

To avoid that you need to protect the script call by braces to let the while command evaluate it.

Try:
Code:
while {[file exists $file.lck]} { wait 1 }
and all should be fine.

Good luck

ulis
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top