lkml.org 
[lkml]   [1998]   [Feb]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: threads and file locking doesn't work correct
Date

Hello,

> > 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).

I haven't tried 2.0.33, I use 2.1.85. I create the lock in the main thread,
and I could remove it in another thread (I think this was possible in
2.0.33, too. But I'm not sure).

The problem is, that the lock will not always be removed if the program
exit. Normally, the lock should be given free, if the program exits. But
that doesn't happen always. In the moment I start a thread which acts as
signal handler and wait for signals which would kill a thread, and then
give the lock free. This works in 9 from 10 cases, but not always.

The problem is, after this, you have a locked file which is owned by a non
existent pid, and you couldn't access /proc/locks without core dump
and kernel oops.

Using flock isn't a solution, since the other, single threaded programs
uses fcntl, too.

Thorsten

--
Thorsten Kukuk kukuk@vt.uni-paderborn.de
http://www-vt.uni-paderborn.de/~kukuk/
Linux is like a Vorlon. It is incredibly powerful, gives terse,
cryptic answers and has a lot of things going on in the background.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu

\
 
 \ /
  Last update: 2005-03-22 13:41    [W:0.081 / U:0.320 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site