read() without changing atime ?

Hey,

First of all I want to know How do I see the atime of a file ?? Whats the command ??

I think ls -l shows the last modified time right ? Because when I use cat to read a file, the timestamp shown by ls -l does not change.

Its not ls -lu ! man ls did not help ! How do I see the last access time of a file in unix ???

Now my next question is:

My C program reads a file using read(). But I do not want the last access time of the file to change. So, I am using utime() to update the atime and mtime of the file back to what it was before the read.

But the problem, the update will fail if the program does not have write permissions on the file. If the file is read only, the program will not be able to modify its attributes (am I right ?).

can you guys please help me out here :slight_smile:

thanks,
Varun

ls -lu is the command to check the atime.create a file and then wait a minute to do cat on it and check.
if all the read and creation happened in the same minute then ls -lu will report the same time.

You are right, you must have write permission to update atime and/or mtime. Bear in mind that such an update will set ctime and you cannot restore ctime. (ls -lc will show ctime)

If you mount a file system read-only atime will not be updated. Some filesystems have a mount option to inhibit atime updates (which is intended to improve performance.) No other way that I know of.

Guys, why is the atime not changing ? I use cat to read the file.. why the hell does the atime not change :frowning: is there some setting that I need to change ? Also, if I use read in my program, the atime does not change..

% uname -a
SunOS 5.8 Generic_108528-29 sun4u sparc SUNW,Sun-Fire-480R
% date
Sun Apr 8 17:32:09 PDT 2007
% vi file <--------------------------------------- just create a file
% ls -lu file
-rw-rw-r-- 1 varkm 15 Apr 8 17:32 file <----- note the access time
% date
Sun Apr 8 17:35:45 PDT 2007
% cat file
This is a file
% ls -lu file
-rw-rw-r-- 1 varunj 15 Apr 8 17:32 file <---- acc time did not change
%

Now whats weird is that If i do the same thing on a GNU/Linux machine, the cat changes the access time the first time. Any cat after that does not change the atime.

Please help.. I have been breaking my head over this since a long time

Thanks in advance !!!

Did you miss "Some filesystems have a mount option to inhibit atime updates"? Sometimes I wonder why I bother typing stuff in. :frowning:

Well, for those who actually read what I write, Solaris ufs filesystems such as exist on Solaris 8, have such an option and it is mentioned on this page.

Hey Perderabo, I am not mounting anything.. I just created a file on my home directory.

(do u mean that my home directory was mounted with no atime updates ?? I never made use of any nfs mount command explicitly)

I examined the /etc/mnttab which contains the table of mounted file systems (mentioned in that link) If this table shows what optins were used to mount my home directory, then I did not see anything such as 'noatime' against my home dir as the mount point. (The options I saw were: nfs rw,intr)

I appreciate your reply Perderabo.. I really dont know whats going on here..

Thanks again :slight_smile:

Also, in my home dir I did a nfs mount of a file from a storage system. I did not specify any noatime option but yet the atime is not changing for thie file on doing a cat.

You can't use a filesystem unless it is mounted. If you didn't mount it, you should ask your system admin to explain the local policy to you. I cannot explain your network to you because I don't know how it is setup. You didn't seem to think that the use of nfs was worth mentioning. With nfs, the situation is even more complex. Attributes may be cached on the client and the over on the server the filesystem is mounted locally and it will have its own options that come into play. At this point I wonder if the server is even running unix. There are a lot of options for delaying or inhibiting atime. If atime is very important to you, you will need to ask your local system admins to change the local setup.

hmm..

thanks for your time Perderabo, I will see what I can do.. try and contact the system admin..

really appreciate your help !!!!