- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Is the file already open by another process ?
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2002 06:50 AM
06-06-2002 06:50 AM
Can someone tell me how I can check if a file is not already open by another process ?
I am using a pipe to communicate between 2 different script. 1 of the script is started from the inittab (user root) and read from the pipe, the other one start from the cron each 15 minutes (user oracle) and is writing to the pipe.
I need to make sure another process is not writing to the pipe at the begining of the script (to avoid 2 simultaneous run of the script for example).
Any idea ?
Many thanks,
Chris.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2002 06:53 AM
06-06-2002 06:53 AM
Re: Is the file already open by another process ?
From a script, which I assume isn't perl? then I'd use "lsof"
http://hpux.cs.utah.edu/hppd/hpux/Sysadmin/lsof-4.61/
w/perl you can check the status of a file to see if it is open already.
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2002 06:54 AM
06-06-2002 06:54 AM
Re: Is the file already open by another process ?
# lsof | grep $FILENAME
Hope this helps. Regards.
Steven Sim Kok Leong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2002 06:56 AM
06-06-2002 06:56 AM
Re: Is the file already open by another process ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2002 06:56 AM
06-06-2002 06:56 AM
Re: Is the file already open by another process ?
LSOF is the utility which can help you .
ftp://vic.cc.purdue.edu/pub/tools/unix/lsof/
is the place to get it from , they ahve a binary version too , incase you cvan get it please do let me know and I will email it to you .
Manoj Srivastava
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2002 06:58 AM
06-06-2002 06:58 AM
Re: Is the file already open by another process ?
You can download the lsof utility from :
ftp://vic.cc.purdue.edu/pub/tools/unix/lsof
then do a lsof | grep filename
Piyush
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2002 06:58 AM
06-06-2002 06:58 AM
Re: Is the file already open by another process ?
# fuser -u
Man "fuser" for details.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2002 07:11 AM
06-06-2002 07:11 AM
Re: Is the file already open by another process ?
Thanks for your answers.
I have used lock directories in the past, but the issue with that being : If a previous run did not terminate properly and the trap did not remove the directory (yes, that's happend to me) the next run never start !
So, I have tried another idea with a open file: If the file is still open, return, else open the file.
Impossible to use fuser as one of the user is not root.
I have already tried lsof, but look like taking a lot of ressources for a simple operation...
Any other suggestion
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2002 07:42 AM
06-06-2002 07:42 AM
Re: Is the file already open by another process ?
Even I am facing the same problem.Now I have an idea.
Store the inode number of all the files whichever u open in list.
Doing a stat on the filename we can get the inode number.
Whenever you open a file check if the inode number is in the list.If it is there then it states that the file is open.
Note: Whenever the file is closed the corresponding inode number should be removed from the list.
I think this might solve the problem.
You might get a better solution.If so then do reply for my query.Subject of my query is
"How can I find the open status of the file?"
Regards
Tharangini
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2002 08:34 AM
06-06-2002 08:34 AM
Solutionto solve the script co-ordination problem as well as the exclusive access problem, I made a solution using file locks.
A C-program takes a file lock (see man fcntl) on a dedicated regular file per resource, then execs the script (the name and arguments of which are arguments to the wrapper program). The file lock is relyably released iff the process exits.
Regards, Klaus
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2002 08:57 AM
06-06-2002 08:57 AM
Re: Is the file already open by another process ?
With lsof, just try,
lsof /path_to_file/file_name
Hope this helps.
Regds
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2003 05:16 PM
08-06-2003 05:16 PM
Re: Is the file already open by another process ?
I resolved my file-open issues with fuser (fuser -cu /u06)
Cheers!
Leon