What is the purpose of lock file? [duplicate]

I have seen a file named lock in /var/cache/apt/archives in my Ubuntu 14.04. This file has only root access. When I try to display the contents of this file using sudo nano lock the file seems empty. What is actually the purpose of this file?


The lock file you mention is used to avoid running more than one instance of any software able to add packages (apt-get, aptitude, synaptic, ...).
This is necessary because the list of installed software is saved in DB file. Having more than one process accessing this DB will lead to corruption into it and break your installed software DB.

Lock files are created by a program when it is necessary to have only one instance of this program running at the same time.
Generally, this is to avoid that local files/DB are accessed concurrently because this may corrupt them.