Re: Safe unlocking
Jens.Toerring_at_physik.fu-berlin.de
Date: 11/28/03
- Next message: Vladimir Zolotykh: "Re: Safe unlocking"
- Previous message: those who know me have no need of my name: "Re: Safe unlocking"
- In reply to: Vladimir Zolotykh: "Safe unlocking"
- Next in thread: Vladimir Zolotykh: "Re: Safe unlocking"
- Reply: Vladimir Zolotykh: "Re: Safe unlocking"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 28 Nov 2003 12:26:41 GMT
Vladimir Zolotykh <gsmith@eurocom.od.ua> wrote:
> Suppose my program starts with creating and locking the file as the
> follows:
> if ((fd = open(file_name, O_CREAT | O_WRONLY | O_EXCL, 0644)) < 0
> || flock (fd, LOCK_EX | LOCK_NB) < 0)
> abort();
> Actually this is C++ program and creating and removing lock file and
> its locking implemented as constructor and destructor. When the
> program terminates properly all works fine and lock file successfully
> removed. The problem arises when the program is terminated by a
> signal. For example if the program is terminated by SIGSEGV or SIGABRT
> the destructor is not called and the lock file remains locked after
> the program termination.
Since when flock() does create a lock file? Unless the flock() function
is something you wrote yourself instead of using the system call there
won't be a lock file, the kernel sets some bits in the open file table
entry for the file. And when your program exits (by whatever way) the
file gets closed automatically and the lock vanishes leaving no traces.
If you really have a lock file you need to get rid of register an
atexit() function to be called when the function exits (but, of
course, this won't be called on a SIGKILL signal, but than that's
a case where also a signal handler woudn't help you).
Regards, Jens
-- \ Jens Thoms Toerring ___ Jens.Toerring@physik.fu-berlin.de \__________________________ http://www.physik.fu-berlin.de/~toerring
- Next message: Vladimir Zolotykh: "Re: Safe unlocking"
- Previous message: those who know me have no need of my name: "Re: Safe unlocking"
- In reply to: Vladimir Zolotykh: "Safe unlocking"
- Next in thread: Vladimir Zolotykh: "Re: Safe unlocking"
- Reply: Vladimir Zolotykh: "Re: Safe unlocking"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|