- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Open status of a file
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
Discussions
Discussions
Forums
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
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-05-2002 05:14 AM
тАО06-05-2002 05:14 AM
How can we find open status of a file?Is there any structure which tells us abt the file's open status.Each time when we open a file I think some reference count is incremented (which is used by unlink) Can we access that count.In the stat structure we have a field which gives us number of hard links. some thing like that which tells how many times a file is opened.Can we access the structure struct inode which is in inode.h.Is there any field in that structure which gives me the open status of the file or the number of times the file is refered?
Please do reply for these questions.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-05-2002 05:26 AM
тАО06-05-2002 05:26 AM
Re: Open status of a file
Look at its -f or +f option, it shows file structure use count.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-05-2002 07:13 AM
тАО06-05-2002 07:13 AM
Re: Open status of a file
Assuming this is an extension of your earlier question, you really should rethink the process and use advisory file locking - a much more portable solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-06-2002 08:36 AM
тАО06-06-2002 08:36 AM
Re: Open status of a file
Thank you for replying me.
But still i am not getting the correct solution.
When I go for advisory locking only if the process are different my second lock fails,if it is of same process it cooly locks.
Why there is no any way to access the reference count of a file?
Tharangini
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-06-2002 09:05 AM
тАО06-06-2002 09:05 AM
Re: Open status of a file
Even if the current open count could be easyly determined, it is not clear, if the count would be correct, if the file is used twice in the same process.
It would not be relyable to use this counter anyway, because it cannot be guaranteed, that it increases after it has been inquired, and before your process accesses.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-06-2002 10:38 AM
тАО06-06-2002 10:38 AM
Re: Open status of a file
My plan is to use the flag for the same process
AND to use lockf() as well to lock the file for other processes. That should cover you in all cases.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-06-2002 03:23 PM
тАО06-06-2002 03:23 PM
Solution#define STDERR_FDES 2
struct stat s1,s2;
/* Get the maximum possible fdes */
nfiles = (int) sysconf(_SC_OPEN_MAX);
fdes = open(fname,O_RDWR,0600);
cc = fstat(fdes,&s1);
i = STDERR_FDES + 1
fnd = FALSE
while (i < nfiles && !fnd)
{
if (i != fdes)
{
cc = fstat(i,&s2);
if (cc == 0) /* valid fdes */
{
fnd = ((s1.st_dev == s2.st_dev) &&
(s1.st_ino == s2.st_ino));
}
}
if (!fnd) ++i;
}
if (fnd)
{
printf("File was already open\n");
(void) close(fdes);
}
else
{
printf("File was not opened\n");
}
The idea is that we determine the maximum possible fdes and loop thru the valid fdes's
looking for match device and inode numbers. If we find them, the file is already open.
I still don't know why a flag can't be used but the above method will work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-08-2002 12:34 AM
тАО06-08-2002 12:34 AM
Re: Open status of a file
Thank u every one for replying me.
Clay,
actually I am not interested in using flags .That's why I was not convinced with that solution.I'll go ahead with ur last solution.Even I had the same solution.
Thank u .
Tharangini