Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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
up vote 4 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.

      echo "fopen: " .date("H:i:s \n");
      $fh = fopen('test.tmp', 'r');
      echo "fread: ".date("H:i:s \n");
      echo "fwrite: ".date("H:i:s \n");
      echo "fclose: ".date("H:i:s \n");
      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.


    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.

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

You have to open the file with 'w' for write to work:

$fh = fopen('test.tmp', 'w');
share|improve this answer

Your Answer


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.