943,746 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 1984
  • C RSS
Mar 20th, 2008
0

I need file lock mechanism in Linux platform

Expand Post »
Hi all
there is a Windows API function as
  1. HANDLE CreateFile(
  2. LPCTSTR lpFileName,
  3. DWORD dwDesiredAccess,
  4. DWORD dwShareMode,
  5. LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  6. DWORD dwCreationDisposition,
  7. DWORD dwFlagsAndAttributes,
  8. HANDLE hTemplateFile
  9. );
This function contains argument for share mode.. When I provide it 0 value then no other process can open/access the file already opened while created this call. That is while I have its handle opened if i try to access file through notepad.. it is restricted.
I need to have a similar working in Linux platform. I found two functions given in Linux which are fcntl() and flock() these two provides file locking facility in Linux. But I have tested it by opening a file and then locking it using fcntl() but then when i open the same file through editor or open() system call it is opened and locking is not functional . I need you people's help. I want to have a lock on the file that no process shall be able to open the file while is is locked. plz help me out and suggest me what i am missing.
Regards
Reputation Points: 10
Solved Threads: 0
Light Poster
nabilchampion is offline Offline
25 posts
since Jul 2007
Mar 20th, 2008
0

Re: I need file lock mechanism in Linux platform

On *nix all you have to do is pass the right arguments in the open statement and it will work the same way as CreateFile() odes. check your compiler to see if it has fsopen() because I'm not sure if that function is standard C or not.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,950 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: how can i do this pl!
Next Thread in C Forum Timeline: CHar * variable





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC