LINUX programming

Moderators: ITA
Number of threads: 1347
Number of posts: 2935

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Checking open/close status of files in directory Posted by jre1578 on 31 Jul 2003 at 12:33 PM
My understanding is that 'stat' will find things like mode, file size, time stamps, etc. But not if the file is actually open or not. I need to be able to find all open files in a directory and close them - but not sure if using 'stat' will work. Can someone clarify this for me?
Report
Re: Checking open/close status of files in directory Posted by tihomir on 3 Sept 2003 at 7:51 AM
You won't have much success with this... because this is not Windows.

In Windows you have automatic file locking when opening a file, but in Linux there's no automatic locking, but you must use "flock" to lock it... So guys who use flock will be caught by you, but guys who don't - will slip away...



: My understanding is that 'stat' will find things like mode, file size, time stamps, etc. But not if the file is actually open or not. I need to be able to find all open files in a directory and close them - but not sure if using 'stat' will work. Can someone clarify this for me?
:
Report
Re: Checking open/close status of files in directory Posted by kor on 9 Sept 2003 at 1:31 PM
Try setting an exclusive lock, if the file's open, even if it's a shared lock, you should get an error. Check the section 2 man pages for more info.

: You won't have much success with this... because this is not Windows.
:
: In Windows you have automatic file locking when opening a file, but in Linux there's no automatic locking, but you must use "flock" to lock it... So guys who use flock will be caught by you, but guys who don't - will slip away...
:
:
:
: : My understanding is that 'stat' will find things like mode, file size, time stamps, etc. But not if the file is actually open or not. I need to be able to find all open files in a directory and close them - but not sure if using 'stat' will work. Can someone clarify this for me?
: :
:




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.