File Locking

From CsWiki
Jump to: navigation, search

File Locking

Lock files

Some applications (e.g. firefox, eclipse and more) uses lock files to prevent users from opening two instances of the same application. A lock file is usually a simple file named "lock" or ".lock".
The application creates the lock file when it starts, and delete it when it exits. When it crashes, it might forget to clean up the lock files, and when it is re-opened, and finds the lock files, it thinks there is already an instance running, and as a result, refuses to open.

To fix this, all you have to do is to delete those lock files.

Warning: deleting lock files when the application is running can (and will) cause data loss. (So don't unlock an application just to have two instances running, it will cause more troubles then it solves).

Lock files examples


The firefox lock files are under the account directory, usually ~/.mozilla/firefox/*/.lock. The * represent an account in firefox (if you have only one, it will usually be some random string ending with .default). Sometimes there will also be a .parentlock file that you'll have to delete as well.


The thunderbird lock files are similar to firefox's lock files. They reside under ~/.mozilla-thunderbird/*/.lock, and have a lock for each account. Here also, there might be a .parentlock to be deleted.


Eclipse has it's lock files under each workspace you create (you shouldn't create a lot of workspaces, as they use up a lot of space, for more information please look at the eclipse section in the disk space page).
Under the workspace, the lock file is at <workspace>/.metadata/.lock

The unlock utility

There is an unlock utility, which will unlock firefox, thunderbird or eclipse for you. Please note that it will delete the lock files for all accounts or workspaces. So if you have one account/workspace opened, and you want a different one opened (but it is locked), you'll have to manually delete it.

To use it simply execute:

unlock <program>

To see the available programs it can unlock, use:

unlock -h