The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
close open files before remove xramm SUN Solaris 9 09-14-2007 08:23 AM
Installing RedHat 8.0 onto Dell PowerEdge SC1425 - hdc: status error: status = 0x58 fishsponge Red Hat 5 07-14-2006 02:53 PM
check the status and send an email with status isingh786 Shell Programming and Scripting 3 12-29-2005 07:22 PM
Should a UNIX daemon process close open fds? kunalashar UNIX for Dummies Questions & Answers 1 10-24-2002 09:10 AM
Couldn't open status file /var/samba/STATUS.LCK macdonto UNIX for Dummies Questions & Answers 2 08-08-2001 08:42 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-26-2001
Pal Pal is offline
Registered User
  
 

Join Date: Sep 2001
Posts: 3
File status - open/close ??

Is there any commands in UNIX, like isopen(),isclose() to know whether a file has been opened for read/write purpose.?

Thanks
  #2 (permalink)  
Old 09-26-2001
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
fcntl() can tell you if a open file has read-only, write-only, or read-write access modes set during the open(). It will fail on a closed file.
  #3 (permalink)  
Old 09-26-2001
rwb1959's Avatar
rwb1959 rwb1959 is offline
Registered User
  
 

Join Date: Aug 2001
Location: Virginia, USA
Posts: 438
I'm not sure but I think you're asking if one process
can tell if a file was opened for read/write by another
process... correct?

In the function...
int fcntl(int fildes, int cmd, /* arg */ ...);

fildes must be a file descriptor to an open file
therefore, in order to use this, the current (or parent)
process should have already opened the file so you should
not get a "closed" file error.

You can use fcntl() to try to set an exclusive lock on a file
that you have previously opened and if another process
has opened this file for write access, fcntl() will fail. However,
if the other process has not opened the file for write access
and just for reading (i.e. O_RDONLY), then fcntl() will not fail.

Anyway, this is all system call level stuff.
If you're looking for a command line program to tell you
if a file is open or not, try lsof (LiSt Open Files) look at:

http://www.ensta.fr/internet/unix/sys_admin/lsof.html
  #4 (permalink)  
Old 09-26-2001
Optimus_P Optimus_P is offline Forum Advisor  
flim flam flamma jamma
  
 

Join Date: May 2001
Location: Chicago IL, USA
Posts: 1,006
you chould also look into lsof. it is an external program you install and it will List all Open Files.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:23 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0