Subj : Re: Opening a file in exclusive mode To : comp.os.linux From : ganesh.m Date : Thu Jul 29 2004 10:48 pm vanjina_murthy@rediffmail.com (murthy) wrote in message news:<1d1f73fd.0407280615.4db78145@posting.google.com>... > I am developing an application using C > > I am facing a problem , when a file is opened by one process either in > read/write mode using open function , at the same time the other > process can delete the same file using unlink function. > > What i want is that if a file is opened by one process either for > reading/writing it should not be deleted or even can be opened by > other process(i.e open should fail). Anyone knows, how it can > achieved. > > The purpose is that i want to open a file in exclusive mode. > > Thanks in adavance > > Murthy Hi Murthy! Record/File locking (using flock() fcntl()...) can be used to obtain exclusive control over a (part of a) file. But this works among co-operating processes only. means each of the processes should try to obtain a lock bfore using the file. This is advisary but not mandatory... means a process can still have control on the file illegally. Em... If ur system supports mandatory record locking (This is done by stting some special flags in the files access-mode)... But even this also cannot prevent a process from deleting the file... Plzz let me know... If at u get some solution for this... Thanks... - Gana .