Operating System - HP-UX
1834771 Members
3288 Online
110070 Solutions
New Discussion

checking reference count of directory file open

 
danysis
New Member

checking reference count of directory file open

Hi Gurus

I have problem , how can you check , whether one directory is opened by anothere process in
HP-ux

answer expected early

see problem is

I have one directory file /tmp which is opened by one process, when second process tries to open the directory /tmp , it should not allow
How can i check whether directory is opened by other process


cheers
danysis
6 REPLIES 6
James Murtagh
Honored Contributor

Re: checking reference count of directory file open

Hi Danysis,

I think you're looking for the fuser command, i.e. :

# fuser -u /tmp

This will list the process ids - check the manpage for full details. There is also an opensource tool called lsof which is a lot more powerful - its available here :

http://hpux.connect.org.uk/hppd/hpux/Sysadmin/lsof-4.70/

cheers,

James.
T G Manikandan
Honored Contributor

Re: checking reference count of directory file open

#fuser -cu /tmp

That should list down the processes.
danysis
New Member

Re: checking reference count of directory file open

Hi
Thnx for mail

But i want system call which , normal user can use to check , how many instances of directory file is opened by a process

but for fuser commond , you should run as a root , i suppose

My problem is, i want to check whether a directory is opened by another process
James Murtagh
Honored Contributor

Re: checking reference count of directory file open

I don't think this will be possible without compromising security too much. Is there a call on another system that can do this?

What you could do is write a daemon process that could do the work (through pstat) and have the user's query this, while having it take care of the authentication. A bit of work but if needs must....

- James.
Elmar P. Kolkman
Honored Contributor

Re: checking reference count of directory file open

You could try to open the file/directory in exclusive mode (O_EXCL option on the open system call) but this will not always work (some NFS implementations ignore it, for instance). But it might help solve your problem: don't count number of open sessions, but block multiple instances of same program to use the same dir/file.
Every problem has at least one solution. Only some solutions are harder to find.

Re: checking reference count of directory file open

Hi danysis,

Try this :

lsof +D /tmp

Best regards