Find the answer to your Linux question:
Results 1 to 4 of 4
I need the 'last access time' of a file in microseconds . Struct stat returns the time in seconds . Is there any other way to get access/modified time of ...
  1. #1
    Just Joined!
    Join Date
    Mar 2010
    Posts
    3

    [SOLVED] file properties - last access/modified time

    I need the 'last access time' of a file in microseconds.
    Struct stat returns the time in seconds. Is there any other way to get access/modified time of files?

    struct stat sb;
    if(stat(filename.c_str(), &sb) != -1)
    {
    time_t accesTime = sb.st_atime; //accessTime in seconds

    ...some code...
    }

  2. #2
    Linux Guru Lakshmipathi's Avatar
    Join Date
    Sep 2006
    Location
    3rd rock from sun - Often seen near moon
    Posts
    1,568
    If I'm not wrong,ext3 file system saves timestamps in seconds - Only ext4 saves timestamp in nano seconds.

    If you need ext3 timestamp in other format , you can convert it (from seconds to micro/nano seconds ) manually in your code.
    - Lakshmipathi.G
    -------------------
    FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
    First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
    -------------------

  3. #3
    Just Joined!
    Join Date
    Mar 2010
    Posts
    3
    Quote Originally Posted by Lakshmipathi View Post
    If I'm not wrong,ext3 file system saves timestamps in seconds - Only ext4 saves timestamp in nano seconds.

    If you need ext3 timestamp in other format , you can convert it (from seconds to micro/nano seconds ) manually in your code.

    Thanks for your reply.
    I have some files which have same 'access time' in seconds. If I read those times in seconds and convert it manually to microseconds (seconds*pow (10,6)), I'll get the same access time for all files again.
    I wanted to read the access time more precisely.

  4. #4
    Linux Guru Lakshmipathi's Avatar
    Join Date
    Sep 2006
    Location
    3rd rock from sun - Often seen near moon
    Posts
    1,568

    Post

    Quote Originally Posted by gmsa View Post
    Thanks for your reply.
    I have some files which have same 'access time' in seconds. If I read those times in seconds and convert it manually to microseconds (seconds*pow (10,6)), I'll get the same access time for all files again.
    I wanted to read the access time more precisely.
    Again , I'm not wrong you can't achieve your requirement with ext3 file system. May be you can check all timestamps like ctime and mtime and combine to them to get results - if that's not suitable to your program,you need to go for file systems that supports micro/nano timestamp.


    HTH
    - Lakshmipathi.G
    -------------------
    FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
    First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
    -------------------

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...