Solved

Linux File Locking on Network Files

Posted on 2014-11-13
4
214 Views
Last Modified: 2014-11-19
I am try to implement a file locking system within my application which is running in Linux.

I use flock to lock the file as shared (LOCK_SH) when reading and as exclusive (LOCK_EX) when writing.  I'm also perform the lock as non-blocking (LOCK_NB).

I tested the file locking of a networked file by running 2 instances of my application on the same PC simultaneously, and I can see that one will wait to write while the other is in the process of writing.

When I run one instance on one PC and another instance on another PC, I am unable to see that the either PC recognizes the network file as locked.

What is the proper way to get networked PCs to recognize when a file is locked?

I am currently running Fedora 19 and my application is written in C.
0
Comment
Question by:sctccomm
  • 2
4 Comments
 
LVL 33

Accepted Solution

by:
sarabande earned 450 total points
ID: 40442064
you may think of setting up an nfs file system. see

http://nfs.sourceforge.net/

for more information.

Sara
0
 
LVL 34

Assisted Solution

by:Duncan Roe
Duncan Roe earned 50 total points
ID: 40442179
When you mentioned networked file I assumed you were using NFS already. Is that not the case?
man nfs has quite a lot to say about file locking, especially between different clients
0
 

Assisted Solution

by:sctccomm
sctccomm earned 0 total points
ID: 40443921
I was able to get the file locking to work.

Originally I used:  mount -t cifs //192.168.1.100/project /mnt/project

but this is just normal Windows file sharing, not NFS.

After installing and configuring NFS on my Windows server, I mounted the drive using:

mount -t nfs 192.168.1.100:/project /mnt/project

Now everything is working as expected.
0
 

Author Closing Comment

by:sctccomm
ID: 40451911
Setting up an actual NFS was the solution.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
AWS EC2 Linux 1 55
Linux hostname change 2 55
How to update  and reset admin password for Linux 5 45
expectj telnet failing 5 26
The CRUD Functions CRUD, meaning "Create, Read, Update, Delete (http://en.wikipedia.org/wiki/Create,_read,_update_and_delete)" is a common term to data base developers.  It describes the essential functions of data base table maintenance.  This art…
What is Waterfall Model? Waterfall model is the classic Software Development Life Cycle method practiced in software development process. As the name "waterfall" describes, this development is flowing downwards steadily like waterfall, i.e., procee…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now