Operating System - HP-UX
1827262 Members
2056 Online
109717 Solutions
New Discussion

How to get number of referenced fd??

 
Herbert Simon
Advisor

How to get number of referenced fd??

Hello!

I want to know how many processes have a reference via open() to a given file. This file can be resist in an NFS-share or local.
I know that there must be a conter for that but i don't know how to access it..
Anybody for a good idea??

Thanks a lot!

Karsten
7 REPLIES 7
Steve Steel
Honored Contributor

Re: How to get number of referenced fd??

Hi

go to

http://hpux.connect.org.uk/

look at lsof and libevent-0.4

Ths sources should help

Steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)
Stephen Keane
Honored Contributor

Re: How to get number of referenced fd??

and don't forget to assign points to those that have helped you.
Herbert Simon
Advisor

Re: How to get number of referenced fd??

Hi, Thanks for your help.

lsof is verry mighty and total overdone for my (simple) request. To parse the source ( ~ 80.000 lines ) to get the necessary information is a little bit to hard for me :-)

Karsten
Peter Godron
Honored Contributor

Re: How to get number of referenced fd??

Herbert,
another method would be to use fcntl() with the f_getlk parameter to search for the lock on the file.
Using the l_type and l_pid from the flock structure would give you the process id.
Regards
Gordon  Morrison
Trusted Contributor

Re: How to get number of referenced fd??

Have you tried

fuser filename

?
What does this button do?
Herbert Simon
Advisor

Re: How to get number of referenced fd??

Hi Peter!

Well, F_GETLCK don't helps if the other process do not do a lock to the file. I played with this solution but i don't want to use file locks over NFS ( NEVER do this.. expactly with HP :-( we have a lot of verry bad experiences with it)
At least I need a save( realy save ) way to synchronise a process after a file is fully written by a external process ( 3D Application ) without lost seconds to wait if mtime/ctime isn't more changed.The write can take a lot of seconds ( big files over NFS which runs over smal leased Lines). The idea is to check the number of open references ( filedescriptors ) to this file. If it is zero
i know the write is done.

regards
Karsten
Gordon  Morrison
Trusted Contributor

Re: How to get number of referenced fd??

WOOHOO!
I got a hat!
:oD
What does this button do?