Thursday, May 9, 2024
 Popular · Latest · Hot · Upcoming
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 551  / 2 Years ago, wed, december 8, 2021, 3:28:33

I can see there are many lock file here and there in my system. What is the exact role and purpose of those lock files?



In my system I got this list,



/run/lock/whoopsie/lock
/proc/sys/dev/cdrom/lock
/var/lib/dpkg/lock
/var/lib/apt/lists/lock
/var/cache/apt/archives/lock

More From » lock

 Answers
7

They are all lock files. Link for more information.



Different applications and daemons create their lock files, if they need to protect themselves from crashing or from corrupting information.



For example:



/run/lock/whoopsie/lock


lock for whoopsie, it is Ubuntu Error Reporting daemon. It collects information about crashes, so it need to protect some information from changes until it collects everything.



/proc/sys/dev/cdrom/lock


Lock file for you cdrom device. Only one application at a time can control cdrom device, that's why it is there. The same thing for every devices.



/var/lib/dpkg/lock
/var/lib/apt/lists/lock
/var/cache/apt/archives/lock


Lock file for package managers. They usually blocking their sources database



Also a little quote from wikipedia:



The following example illustrates the interceding update problem:





  1. Process A reads a customer record from a file containing account information, including the customer's account balance and phone
    number.


  2. Process B now reads the same record from the same file so it has its own copy.


  3. Process A changes the account balance in its copy of the customer record and writes the record back to the file.


  4. Process B, which still has the original stale value for the account balance in its copy of the customer record, updates the account
    balance and writes the customer record back to the file.


  5. Process B has now written its stale account-balance value to the file, causing the changes made by process A to be lost.





This is one of examples. There many other situations that can lead to a problem. That's why OS need lock files


[#27330] Wednesday, December 8, 2021, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
girdleas

Total Points: 1
Total Questions: 112
Total Answers: 114

Location: Lesotho
Member since Wed, Jun 2, 2021
3 Years ago
;