1

when I open a file , and the program creates this file, what does this lock file do ? is it a prevention from simultaneous run ?

<?xml version="1.0" encoding="UTF-8"?>
    <LockFile>
      <CreationData>
        <Data AccessMode="w"/>
        <Data Host="VAIO"/>
        <Data Process="56496"/>
        <Data Time="05/02/2016 23:59:03"/>
        <Data User="ddd"/>
      </CreationData>
    </LockFile>
bwDraco
  • 46,155
Farzad64
  • 163

1 Answers1

2

Lock files are used to prevent Race Conditions, a situation that occurs when two processes that share/change the same resources run at the same time and can cause unexpected effects.

Programs will implement lock files in their own way, which usually will prevent you from running or opening a second instance of the file, or forces the second instance to be in a read only mode to prevent both instances altering the source.

Most Microsoft Office files create a hidden lock file in the same location of the source file (unless the file is set up for sharing), and will cause a message to show as follows:

enter image description here

enter image description here

These options allow you to open a file as read only, or to show a message once the lock file has been removed.

The program itself will implement and handle lock files in it's own way, so the behaviour, although typically like this, may implement different methods of handling lock files.

More information: File Locking, Lock (Computer Science) and, to some extent, Mutual Exclusion (Mutex)

Jonno
  • 21,217
  • 4
  • 64
  • 71
  • thank you so much , shall I ask , in which file types , I can file the lock file creation ? – Farzad64 Feb 06 '16 at 08:37
  • 1
    @Farzad64 There is no specific format or standard, it's up to the program itself. For Microsoft office, it'll be a hidden file prefixed with "~$" as per my image. It's impossible to say for anything else, they could be .lock files, it may not even be a file but a database somewhere. – Jonno Feb 06 '16 at 08:39
  • so it's mostly hidden ? and it's programming language could be any ? – Farzad64 Feb 06 '16 at 08:40
  • 1
    @Farzad64 It's entirely up to the developer. Your post shows a file of XML format, storing some basic information to validate the lock itself. It could literally be an empty file with any name, in any location. It's up to the developer. – Jonno Feb 06 '16 at 08:41