user2836797
user2836797

Reputation:

How can I see how many times I have used fopen on a file?

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

Answers (3)

tejas
tejas

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

Rahul R Dhobi
Rahul R Dhobi

Reputation: 5806

you can run lsof -p pid of your process to verify opened file from your process

Upvotes: 0

Some programmer dude
Some programmer dude

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

Related Questions