LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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.

Notices

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

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


Hi,

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?

-Ravee.
 
Old 11-20-2007, 10:49 PM   #2
FragInHell
Member
 
Registered: Sep 2003
Location: Sydney Australia
Distribution: Redhat, Centos, Ubuntu
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, 04:08 AM   #3
salasi
Senior Member
 
Registered: Jul 2007
Location: Directly above centre of the earth, UK
Distribution: SuSE, plus some hopping
Posts: 3,910

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


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


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration