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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple sessions writting to file 1

Status
Not open for further replies.

jhahs

Technical User
Oct 19, 2004
29
US
I am having trouble with multiple sessions writting to the same file. I keep losing info and complete entries. I think I have a timing issue with the sessions stepping on each oither as they try to access the file. I have no idea as how to stop the sessions from stepping on each other. Below is the coding that I am using now. Thanks

proc WriteLog {fileName msg} {
while 1 {
if {[file exists $fileName]} {
if {![catch {open $fileName a} fn]} {
puts $fn $msg
flush $fn
close $fn
return
} else {
continue
}
} else {
if {![catch {open $fileName w} fn]} {
puts $fn $msg
flush $fn
close $fn
return
} else {
continue
}
}
}
}
 
Yeah. I'd imagine you would.

#1 solution: Each instance creates a lockfile and deletes it once the write is complete. All other instances respect this convention and look for the lockfile. You catch exceptions
and make sure that in case of unnatural death the lockfile is unlinked.

#2 solution: You use an intermediate provisioner via IPC, say
a socket, to allow operations on the file, the operation is
performed by the intermediate process which has correct permissions to access the file while clients do not.

It's all fairly complicated and though I do it for a living
it still sucks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top