Re: threads and file locking doesn't work correct

Berend Reitsma (
Tue, 24 Feb 1998 12:28:12 +0000 (WET)

On Tue, 24 Feb 1998 wrote:
> I have a big problem with file locking and threads under Linux.
> Before I start threads, I create a pid file which will be locked with fcntl.
> After killing the program (killall or Ctrl-C), the lock will not be
> removed always. When starting the program again, I get the error message,
> that pid <xxx> owns the lock, but there is no program running with this pid.
> Any chance to fix this ? I need threads and file locking.

The problem is that the lock cannot be removed by another thread than the
one that created it (at least in 2.0.33).
Try to use flock in stead of fcntl. This worked for us (partially). Flock
does not check for the PID of the thread that tries to unlock the file.
There are some other problems with dangling locks with more than 2
threads, but I am not sure what causes this problem.

Hope this helps.


Berend Reitsma

United Info B.V. | Phone: +31 (0)513 469100 P.O. Box 10 | Fax: +31 (0)513 461588 8408 ZH Lippenhuizen | Email: The Netherlands | URL:

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to