LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-28-2003, 08:57 PM   #1
xailer
Member
 
Registered: Nov 2003
Posts: 77

Rep: Reputation: 15
File locking in Linux


hi

I don't get the whole atomic file locking.
First,are they called lock files because they restrict access to only program that created them?

Also,lock files act only as indicators and are termed advisory.
Indicators of what?And why are they termed advisory?

thank you

bye
 
Old 12-29-2003, 01:33 AM   #2
Kumar
Member
 
Registered: Sep 2003
Location: Pune, India
Distribution: Red Hat
Posts: 106

Rep: Reputation: 15
These locks are called advisory because locks are only enforced when a program tries to place its own lock; programs that do not attempt
to lock a file may still access it. Locks, therefore, only work between cooperating programs. Hence, it is a way to co-ordinate access between two or more processes trying to access a file. By the way, linux also implements mandatory locking.
 
Old 12-29-2003, 08:28 AM   #3
xailer
Member
 
Registered: Nov 2003
Posts: 77

Original Poster
Rep: Reputation: 15
hi

But with atomic file locking you can't lock or re-lock an existing file?
That means file is locked only for the time of first execution of program and never again?

thank you for your help
 
Old 12-29-2003, 08:48 AM   #4
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Quote:
Originally posted by xailer
But with atomic file locking you can't lock or re-lock an existing file?
That means file is locked only for the time of first execution of program and never again?
That depends. You can lock an existing file, if it not already locked... If you explicitly release the lock somewhere in your program, you can re-lock it after that. In either the same program/process or another.

Also with fcntl() (as opposed to flock() ) you can have multiple locks on different parts of the same file.

Here's another thread about locking that you may want to read.

Last edited by Hko; 12-29-2003 at 08:50 AM.
 
Old 12-29-2003, 11:11 AM   #5
xailer
Member
 
Registered: Nov 2003
Posts: 77

Original Poster
Rep: Reputation: 15
Quote:
Originally posted by Hko
That depends. You can lock an existing file, if it not already locked... If you explicitly release the lock somewhere in your program, you can re-lock it after that. In either the same program/process or another.



Is it allowed to use flock() or fcntl() with F_SETLK command on file locks created with open() function?

thank you
 
Old 12-29-2003, 03:00 PM   #6
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Sure, both fcntl() and flock() need a filedescriptor as one of the parameters (see the man pages). Having a filedescriptor available, means you need to have it opened (and/or created) with open(). Also see the listings in the thread I mentioned, open() is used there as well.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how can I see what programs are locking a certain file ? Menestrel Linux - Newbie 4 07-27-2004 05:25 PM
locking a file permanently sooraj_pathe Linux - General 1 03-11-2004 02:58 PM
locking a usage policy file/ftp file permissions gbow Linux - Newbie 0 02-16-2004 06:35 AM
Wine File Locking MurrayL Linux - Software 3 02-12-2004 04:27 AM
python; file locking TheLinuxDuck Programming 22 08-05-2003 06:47 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:23 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration