read() without changing atime ?

Login or Register for Dates, Times and to Reply

Thread Tools Search this Thread
Top Forums Programming read() without changing atime ?
# 1  
read() without changing atime ?


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 Smilie

# 2  
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.
# 3  
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.
# 4  
Guys, why is the atime not changing ? I use cat to read the file.. why the hell does the atime not change Smilie 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 !!!
# 5  
Did you miss "Some filesystems have a mount option to inhibit atime updates"? Sometimes I wonder why I bother typing stuff in. Smilie

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.

By default, the file system is mounted with normal access time (atime) recording. If noatime is specified, the file system will ignore access time updates on files, except when they coincide with updates to the ctime or mtime. See stat(2). This option reduces disk activity on file systems where access times are unimportant (for example, a Usenet news spool).
# 6  
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 Smilie
# 7  
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.
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #125
Difficulty: Easy
UNIX is a certification of a complete OS system, not only a UNIX kernel.
True or False?

10 More Discussions You Might Find Interesting

1. Solaris

Zfs - what does atime update?

It is widely documented that on zfs atime updates the access time on zfs. Where is the access time updated on Solaris 11.2? If I create file atimetest.txt under rpool/export/home: # zfs list rpool/export/home NAME USED AVAIL REFER MOUNTPOINT rpool/export/home 13.3G ... (5 Replies)
Discussion started by: jabberwocky
5 Replies

2. Shell Programming and Scripting

How to read a dynamically changing file

I want to read a constantly changing file and do some operation on text found in that file. Actually that is log file of linux system and whenever i find a matching string in that file i want to create a text file with timestamp. is it possible to read that file? here is sample output of log... (7 Replies)
Discussion started by:
7 Replies

3. Programming

Changing the way arguments are read from program

I have the following piece of code. Currently the command line arguments are passed as shown below using the "= "sign. I capture the name of the argument, for example vmod and it's corresponding user parameter which is jcdint-z30.cmd. ./raytrac vmod=jcdint-z30.cmd Now I want... (12 Replies)
Discussion started by: kristinu
12 Replies

4. UNIX for Dummies Questions & Answers

-atime not working as expected

I need to sort through a volume that contains video files by access time and delete files that have not been accessed over x days. I have to use the access time as video files are originals that do not get modified, just read Testing commands on a local test folder... $ date Wed Sep 28... (10 Replies)
Discussion started by: canon273
10 Replies

5. UNIX for Advanced & Expert Users

mtime VS atime VS ctime

hi, in trying to maintain your directories, one needs to do some housekeeping like removing old files. the tool "find" comes in handy. but how would you decide which option to use when it comes to, say, deleting files that are older than 5 days? mtime - last modified atime - last accessed... (4 Replies)
Discussion started by: pinoy43v3r
4 Replies

6. Shell Programming and Scripting

Replace characters then read the file without changing it

Hi All At the moment the following code works but ideally i do not want to have to change the original $1 tr "\r" "\n" < "$1" > "$1.fix" printf "\n" >> "$1.fix" mv "$1.fix" "$1" FILE=$1 coffee_out="splitmovie" coffee_fill="-splitAt" coffee_end="-self-contained -o $2"... (1 Reply)
Discussion started by: babajuma
1 Replies

7. Linux

Changing eth3 to read eth0

Hello everyone I recently clone a system and doing so it gave my nics cards id's of eth3 and eth4 instead of eth0 and eth1. Is there a config file or something out there where I can change these back? All help will be appreciated. (2 Replies)
Discussion started by: aojmoj
2 Replies

8. Tips and Tutorials

mtime, ctime, and atime

Unix keeps 3 timestamps for each file: mtime, ctime, and atime. Most people seem to understand atime (access time), it is when the file was last read. There does seem to be some confusion between mtime and ctime though. ctime is the inode change time while mtime is the file modification time. ... (2 Replies)
Discussion started by: Perderabo
2 Replies

9. Shell Programming and Scripting

Problem with changing directory and subdirectories to read only

I have a directory with its subdirectories and files. I want to change them all to read only. Say it is ~/test chmod -R 444 ~/test chmod: `/home/myname/test': permission denied I do not understand. Do I have to have executable mode for a diirectory to access. How can I change ~/test to... (5 Replies)
Discussion started by: lalelle
5 Replies

10. Shell Programming and Scripting

How to read a dynamically changing file and load into Oracle?

I have a tab delimited file which has 27 character fields. The file needs to be loaded into an Oracle table. But the challenge is that everytime the file comes it may or may not have values in all 27 fields. Column Definition of the 27 fields: TYPE: Char (1) NAME: Char (30) CUSTOM_VAL: Char... (8 Replies)
Discussion started by: madhunk
8 Replies

Featured Tech Videos