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
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:
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.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.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:
This is one of examples. There many other situations that can lead to a problem. That's why OS need lock files
They're generally used to ensure only one instance of an application is running at once.
This is particularly important in programs like
apt-get
which may break if more than one instance runs at once.