HP-UX - General

Re: How can I know that a file is being accessed ?

 
SOLVED
Go to solution
Brecht De Baets
Frequent Advisor

How can I know that a file is being accessed ?

Hello,

we have a HP-UX system B.11.23.

I would like to know if I can issue a statement to know if a pdf-file is being accessed by Adobe Reader.

The files are placed on a windows file-server which is mounted in our unix. Sometimes files are accessed by users (mostly using Adobe Reader).

In Windows you cannot delete a file which is being accessed. In unix the file is always deleted, even if it is being accessed. That can be a problem for us.

Is there a way in unix to know whether the file is being accessed ?
17 REPLIES 17
Dave Hutton
Honored Contributor

Re: How can I know that a file is being accessed ?

Could do it two ways. lsof or fuser:
servera:root /opt/ignite/share/doc # fuser diskmirror.pdf
diskmirror.pdf: 3440o

servera:root /opt/ignite/share/doc # ps -ef | grep 3440
root 4202 3472 1 11:08:16 pts/2 0:00 grep 3440
root 3440 3389 0 11:05:05 pts/0 0:03 /opt/Acrobat5/Reader/hppahpux/bin/acroread


Or you could do the same type of thing with lsof | grep diskmirror.pdf

servera:root /opt/ignite/share/doc # lsof | grep -i diskmirror.pdf
acroread 3440 root 24r VREG 64,0x5 67407 17271 /opt/ignite/share/doc/diskmirror.pdf

OldSchool
Honored Contributor

Re: How can I know that a file is being accessed ?

I'm not sure I understand. Given that the file is shared between unix and windows, are you trying to determine (from the unix side) if a someone currently has the file opened in windows?
Shannon Petry
Honored Contributor

Re: How can I know that a file is being accessed ?

This is a somewhat complex issue, but I will try and explain, but it is not really a Unix problem.

In Windoze, a reader accessing the file marks it open. I assume that you are using CFS or something similar to share this Unix file system to multiple users. The Windows file system reports the file being open to the Windows system, but not to Unix.

The Unix side will delete the file do to a lack of a file lock.

You could make an enhancement to Microsoft for proper NFS file system support at version 2 or higher.. But good luck with that one.
Microsoft. When do you want a virus today?
Shannon Petry
Honored Contributor

Re: How can I know that a file is being accessed ?

This is a somewhat complex issue, but I will try and explain, but it is not really a Unix problem.

In Windoze, a reader accessing the file marks it open. I assume that you are using CFS or something similar to share this Unix file system to multiple users. The Windows file system reports the file being open to the Windows system, but not to Unix.

The Unix side will delete the file do to a lack of a file lock.

You could make an enhancement request to Microsoft for proper NFS file system support at version 2 or higher.. But good luck with that one.
Microsoft. When do you want a virus today?
Dave Hutton
Honored Contributor

Re: How can I know that a file is being accessed ?

I must of been a little distracted, but I didn't see Adobe was on windows from a fileshare. I would still assume there would be something from the unix side suggesting that the file was being in use. Instead of my example of the motif version of Adobe localling on the server I had the pdf file, I would think you would see maybe the owner of the file nfs/samba. Unfortunatly I can't mimic what your environment has going.
OldSchool
Honored Contributor

Re: How can I know that a file is being accessed ?

Dave..I'm not sure it is, which is why I asked for clarification from the poster. still waiting....
Brecht De Baets
Frequent Advisor

Re: How can I know that a file is being accessed ?

Hello,

Thanks for the replies so far. I will try to clarify my issue.

We are working with an oracle application server and an oracle database which runs on a Unix server.

We have a windows-file server with pdf-files. We have written an oracle web-application where users can view the pdf-files. I want the pdf-file to be deleted after it is opened (by adobe reader).
The only way I can do this is, is by giving a Unix-command (rm) because I need to write PL/SQL that is turning on my database which is on a unix server.

The problem I am having is that when I issue the rm-command the file is not yet opened on the client, resulting in a 'no file found' (the file is deleted too early). So I need something to test if the file is being accessed, so my application can wait until the the file is accessed and then delete the file afterwards.

Best Regards,
Brecht De Baets
Frequent Advisor

Re: How can I know that a file is being accessed ?

I think it must be possible. With ll -u you can see the time that the file was last accessed.
But I can't use that because I cannot test on the time. I need a status or something that tells me that the file is being accessed.

Is there some statement that gives me a status ?

Regards,
Brecht
OldSchool
Honored Contributor

Re: How can I know that a file is being accessed ?

I don't know of anything on the ux side that will tell you the file is being accessed on hte windows side of the share.

So if you could state what problem you are trying to address, maybe folks here can offer some alternatives.