Reputation:
I am working on a linux system. I have a multi-threaded application that has n
file handles open on a single file f
. How can I see during run-time how many file handles in my process refer to n
?
Upvotes: 1
Views: 181
Reputation: 1925
I think it could be as simple as writing a function
you could make a simple class if you would want, then yo could increment on open and decrement on close and handle other stuff.
long myopen(char* filenmae)
{
static long count = 0;
// open file
// mutex
count++;
// mutex
return count;
}
Upvotes: -1
Reputation: 5806
you can run lsof -p pid of your process
to verify opened file from your process
Upvotes: 0
Reputation: 409166
You could check the symbolic links in /proc/self/fd/
and see if there are multiple descriptors pointing to the same file.
Upvotes: 3