Why is my program creating empty .lck files?

I am trying to use Java Logger. I get a logger file (name.log) with content, it works, and I also get an empty name.log.lck file.

Why does this file appear, what program creates them and how can I remove this behavior?

+7
java logging
source share
4 answers

.lck used by a handler (file handler) to lock a file, to delete this file. Before closing the program, you must close the handler associated with this registration object.

Here is an example of how to close the associated handler:

 for(Handler h:log.getHandlers()) { h.close(); //must call h.close or a .LCK file will remain. } 
+12
source share

lock files are commonly used on Unix / Linux to provide exclusive or consistent access to an important resource.

In this case, the resource is the log file itself — you will not want two or more log instances trying to write to the same log file at the same time. That didn't work at all. Read more about file lock

As Peter Barrett talks about Java Logger:

When the log file is created, a separate lock file is created (in your case) "dbslogfile.txt.lck" is also created. The logger uses this as a mutual exclusion mechanism to access the actual log file.

+3
source share

". lck" sounds suspiciously like a lock file. You did not specify which logger you are using, but in elast one of them uses .lck files for locking - see this answer :

When a log file is created, a separet lock file called (in your case) "dbslogfile.txt.lck" is also created. The logger uses this as a mutual exclusion mechanism to access the actual log file. It doesn't seem to be able to create it (he would need to create a lock file before the log file, of course).

+1
source share

Why are there .LCK files?

On Linux, I had these .LCK files:

 > ls -l -rw-r--r-- 1 el el 4810 Feb 9 2013 mybackground.gif -rw-r--r-- 1 el el 33 Feb 9 2013 mybackground.gif.LCK -rwxr--r-- 1 el el 193 Feb 9 2013 my_file.html -rw-r--r-- 1 el el 33 Feb 9 2013 my_file.html.LCK 

Some programs create these files. You must find out which one. The program that does this will be a program that tries to perform some operation on these files over the network, or perhaps even on this disk. A poorly written program that synchronizes, copies, or deletes files on a disk can choose to use lock files in its work.

The lock file contains the following information:

 eric||my.myemail@hotmail.com 

It is safe to delete .LCK files after the failure of an irresponsible process that left them open. The purpose of these files is to make sure that two processes doing the same thing do not step on each other, causing errors.

Using .LCK files is a bad programming practice that violates the "don't guess it yourself" rule. Creating code that does redundant things to make triple sure that we did it right is a sign that you are a bad programmer .

Any program caught with a red hand clogging up these .LCK files that are hanging should be judged negatively with extreme prejudice.

In my case, it was an automatic synchronization operation of DreamWeaver CS4 that created and opened these files. You will need to delete these files manually, and then find out what action causes these files to remain open, and then send error reports to fix this software.

0
source share

All Articles