Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm just curious; Is atime updated on fread, fopen and/or fclose?

What about mtime? Is it updated on fopen, fwrite and/or fclose?

share|improve this question
1  
Why don't you just try it? Considering that the test program for each case is about 4 lines long, I think your time would have been better spent doing that than writing this question. –  Celada Sep 27 '12 at 13:23
add comment

1 Answer

up vote 2 down vote accepted

If your strace your process, you'll see the fopen and corresponding system stat. To use PHP as an example.

Example with PHP

First make sure the file system is updating these values,

    mount -o remount,atime,diratime /

Then make a small script.

    <?php
      echo "fopen: " .date("H:i:s \n");
      $fh = fopen('test.tmp', 'r');
      sleep(2);
      echo "fread: ".date("H:i:s \n");
      fread($fh,1024);
      sleep(2);
      echo "fwrite: ".date("H:i:s \n");
      fwrite($fh,'test');
      sleep(2);
      echo "fclose: ".date("H:i:s \n");
      fclose($fh);
      echo shell_exec('stat test.tmp');

Then make the test case and execute

    echo test > test.tmp
    php test.php

Which results in ...

    [/]$ php test.php
    fopen: 14:31:34
    fread: 14:31:36
    fwrite: 14:31:38
    fclose: 14:31:40
      File: `test.tmp'
      Size: 5               Blocks: 8          IO Block: 4096   regular file
    Device: 805h/2053d      Inode: 98213       Links: 1
    Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
    Access: 2012-09-27 14:31:36.000000000 +0100
    Modify: 2012-09-27 14:28:28.000000000 +0100
    Change: 2012-09-27 14:28:28.000000000 +0100

So ...

  1. fread should correlate with atime
  2. fwrite should correlate with mtime.

Reference

    mtime: time of last modification    (eg. ls -l)
    ctime: time of last status change   (eg. ls -lc)
    atime: time of last access          (eg. ls -lu)

This is pretty well documented as part of the stat function, ref. http://en.wikipedia.org/wiki/Stat_%28system_call%29

share|improve this answer
    
Thank you so much for this answer! –  Ztyx Sep 27 '12 at 13:59
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.