Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 11-20-2007, 10:42 PM   #1
LQ Newbie
Registered: Sep 2007
Posts: 25

Rep: Reputation: 15
How to know whether a particular file is opened or not?


I have a query regarding Linux files. I would like to know whether a particular file is opened by a process or not?

I have a way to check by getting the process the process id from PS and then chekcing the proc filesystem. But my idea is to check whether the file is opened by any other process or not, to induce locking.

Is there any way to check for the same?

Old 11-20-2007, 11:49 PM   #2
Registered: Sep 2003
Location: Sydney Australia
Distribution: Redhat, Centos, Solaris, Ubuntu, SUSE
Posts: 282

Rep: Reputation: 45
fuser is what your looking for here.

e.g fuser /data/myfile.dat should tell you which process has the file open.
Old 11-22-2007, 05:08 AM   #3
Senior Member
Registered: Jul 2007
Location: Directly above centre of the earth, UK
Distribution: SuSE, plus some hopping
Posts: 4,070

Rep: Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897
Are you looking for something like 'lsof'? You'll probably still need to run the output through 'grep' though.


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
device /dev/dsp can't be opened (No such file or directory) fof3 Linux - Newbie 2 10-27-2007 02:33 PM
How to know whether a dev file has been opened or not? asahlot Linux - Software 2 03-06-2007 12:02 AM
preventing deletion of an opened file sayarsoft Programming 3 02-05-2007 08:05 PM
open SuSE 9.3 Logout from an opened file langbein SUSE / openSUSE 2 11-21-2005 04:19 PM
FAM monitoring file opened/create/copy laikos Programming 0 03-07-2004 03:57 AM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:17 AM.

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