LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > AIX
User Name
Password
AIX This forum is for the discussion of IBM AIX.
eserver and other IBM related questions are also on topic.

Notices


Reply
  Search this Thread
Old 01-13-2012, 03:39 PM   #1
drnick911@yahoo.com
LQ Newbie
 
Registered: Oct 2010
Posts: 3

Rep: Reputation: Disabled
how to check if file is opened?


Hey guys,
How do I check if a file is opened/being used by another process/user in AIX?

Let's say, in one session I have a file opened via vi
% vi /home/user1/testfile.txt

Now in another session, let's say user2, how would they verify that the file /home/user1/testfile.txt is not opened/as being updated before doing anything to /home/user1/testfile.txt ????

From second session, I tried:
% fuser /home/user1/testfile.txt

and the results are coming back for both opened or not opened as:
/home/user1/testfile.txt:

Please help me to get to the correct answer.

Thanks in advance to everyone.

Nick.

Last edited by drnick911@yahoo.com; 01-13-2012 at 03:41 PM.
 
Old 01-13-2012, 03:55 PM   #2
T3RM1NVT0R
Senior Member
 
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, SLES, CentOS, Red Hat
Posts: 2,385

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
@ Reply

Hi drnick911@yahoo.com,

Try running the following command:

Code:
lsof -a / | grep filename
 
Old 01-13-2012, 04:03 PM   #3
sys64738
Member
 
Registered: May 2008
Location: NRW/Germany
Posts: 105

Rep: Reputation: 30
Hi,
I'm not quite sure but I think vi opens the file for reading and the saves it into temporary work file. Then the file is closed.
So you might not find your file open.
I'm not quite sure, but you should try another application to keep your file open.

I hope that will help you
 
Old 01-13-2012, 04:09 PM   #4
sys64738
Member
 
Registered: May 2008
Location: NRW/Germany
Posts: 105

Rep: Reputation: 30
Hi,

I've found something better it is about vim but should also work with vi.
http://vim.1045645.n5.nabble.com/Dis...td1177632.html
 
Old 01-17-2012, 02:31 PM   #5
acid plasm
LQ Newbie
 
Registered: Jan 2012
Posts: 5

Rep: Reputation: Disabled
I don't think vi has a swapfile variable to set...maybe wrong or maybe different versions, but not sure if this applies unless they installed vim manually...


Acid
AIX Commands, Tools, Scripts and Explanations
 
Old 01-18-2012, 12:13 PM   #6
trbennett48
LQ Newbie
 
Registered: Apr 2011
Location: Oregon
Posts: 25

Rep: Reputation: 3
Try
Quote:
fuser filename
 
1 members found this post helpful.
Old 01-20-2012, 06:15 AM   #7
rainbowsally
Member
 
Registered: Oct 2011
Posts: 47
Blog Entries: 138

Rep: Reputation: Disabled
Quote:
Originally Posted by drnick911@yahoo.com View Post
Hey guys,
How do I check if a file is opened/being used by another process/user in AIX?

Let's say, in one session I have a file opened via vi
% vi /home/user1/testfile.txt

Now in another session, let's say user2, how would they verify that the file /home/user1/testfile.txt is not opened/as being updated before doing anything to /home/user1/testfile.txt ????

From second session, I tried:
% fuser /home/user1/testfile.txt

and the results are coming back for both opened or not opened as:
/home/user1/testfile.txt:

Please help me to get to the correct answer.

Thanks in advance to everyone.

Nick.
I think part of the problem may be that files like text files (and executables) are only open for a very short time while being loaded into memory.

Only if changed, do the contents get copied back to the original file (in ths scenario you describe), and again, the files are only open for a short time while writing back.
 
1 members found this post helpful.
Old 01-24-2012, 04:50 PM   #8
sys64738
Member
 
Registered: May 2008
Location: NRW/Germany
Posts: 105

Rep: Reputation: 30
@rainbowsally
yep thats what I think too. vi opens the file just a short time for reading and then after that the file becomes closed again.
 
Old 01-27-2012, 09:28 PM   #9
-=Graz=-
Member
 
Registered: Jan 2006
Location: Australia
Distribution: Fedora, Slackware, RHEL, AIX, HP-UX
Posts: 358

Rep: Reputation: 31
Yep vi will read the file and then create a temporary file in /var/tmp to work with.

I have vi a file called test_file and left it open. I then start a new session and enter the below

[root@server:/root]# lsof | grep test_file
[root@server:/root]# cd /var/tmp
[root@server:/var/tmp]# ls -lrt | tail -1
-rw------- 1 root system 0 28 Jan 13:14 Ex64160
[root@server:/var/tmp]# fuser Ex64160
Ex64160: 9564160
[root@server:/var/tmp]# ps -fp 9564160
UID PID PPID C STIME TTY TIME CMD
root 9564160 8806412 0 13:14:51 pts/1 0:00 vi test_file

Last edited by -=Graz=-; 01-27-2012 at 09:32 PM.
 
  


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
Check which port is opened malickhat Linux - Newbie 5 05-11-2010 03:17 AM
How to know whether a particular file is opened or not? kondrara Linux - Software 2 11-22-2007 04:08 AM
how to check number of opened handles ruj.sabya Linux - General 2 08-06-2007 08:37 AM
How to know whether a dev file has been opened or not? asahlot Linux - Software 2 03-05-2007 11:02 PM
How to check what ports are opened Mic Q SUSE / openSUSE 6 08-23-2005 09:04 PM

LinuxQuestions.org > Forums > Other *NIX Forums > AIX

All times are GMT -5. The time now is 05:11 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