Why are my plists in ~/Library/Preferences accompanied by a matching lockfile in Lion?
$ cd ~/Library/Preferences
$ ls -1 | grep plist | head -10
AddressBookMe.plist
com.adiumX.adiumX.plist
com.adiumX.adiumX.plist.lockfile
com.apple.AddressBook.plist
com.apple.AddressBook.plist.lockfile
com.apple.BezelServices.plist
com.apple.BezelServices.plist.lockfile
com.apple.BluetoothAudio.plist
com.apple.Console.LSSharedFileList.plist
com.apple.Console.LSSharedFileList.plist.lockfile
what are these lockfiles for?
Solution 1:
Apple supplies a Core Foundation Preference Services API to developers that makes it easy for them to manage preferences. Apple uses the same API and these lock files help the system know what programs are writing to the files and it helps the system notify the running program when a setting gets changed.
The system will keep track of a file that's open even if you trash and delete it, but it's probably best to leave these alone (like most of ~/Library) as there's no undo for things that are stored there - they are there to support the "undo" of the rest of the system.
Solution 2:
Lockfiles are used to make sure only one app interacts with a preference file at once. The idea is an app opens the lockfile in an exclusive mode while it opens the plist.
Source:
- Lockfiles and other plist file subtypes in OS X Lion