LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 06-13-2006, 06:27 PM   #1
level3
LQ Newbie
 
Registered: Jan 2006
Posts: 13

Rep: Reputation: 0
Question How to fine file lock on Linux under C?


Hello I am trying to fine file locking (read, and write, individual locked spaces), but my problem is that fcntl seems to not work in threads. Because threads have the same locks (only works in diffrent programs)
I use lockf instead fo fcntl, but program segfault. Could be because file is mmaped?
flock is a very poor interface that seems to work with ptreads because lock de inode and not the file descritor.

Any suggestion are wellcome. Thanks in advance.
 
Old 06-15-2006, 12:13 AM   #2
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,794

Rep: Reputation: 282Reputation: 282Reputation: 282
Personally I would combine fcntl with mutexes. fcntl will take care of locking between programs and mutexes will take care of 'locking' between the threads. Info about mutexes in man pthread_mutex_lock.
 
  


Reply



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
lock a file sailajabhandaru Linux - Software 2 01-02-2006 03:37 AM
why when redirecting output to a file any file extension seems to be fine? dr_zayus69 Linux - General 1 05-21-2005 04:09 AM
How to lock a file satimis Linux - General 2 03-09-2005 05:50 PM
Can't read lock file /tmp/.X0-lock squinn Linux - Newbie 3 07-13-2004 03:42 PM
Lock file ust Linux - Software 1 10-11-2003 02:11 AM

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

All times are GMT -5. The time now is 09:22 PM.

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