0% found this document useful (0 votes)
31 views30 pages

04 7 Amctimes

test

Uploaded by

JohnKevinStanley
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views30 pages

04 7 Amctimes

test

Uploaded by

JohnKevinStanley
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

Advanced Programming in

the UNIX Environment


Week 04, Segment 7:
atime, mtime, ctime
Department of Computer Science
Stevens Institute of Technology

Jan Schaumann
jschauma@stevens.edu
https://stevens.netmeister.org/631/
CS631 - Advanced Programming in the UNIX Environment

struct stat
struct stat {
dev_t st_dev; /* device number (filesystem) */
ino_t st_ino; /* i-node number (serial number) */
mod_t st_mode; /* file type & mode (permissions) */
dev_t st_rdev; /* device number for special files */
nlink_t st_nlink; /* number of links */
uid_t st_uid; /* user ID of owner */
gid_t st_gid; /* group ID of owner */
off_t st_size; data
/* size in bytes, for regular files */
time_t st_atime; /* time of last Vaccess */
data
time_t st_mtime; /* time of lastVmodification */
time_t st_ctime; /* time of last file status change */
long st_blocks; /* number of 512-byte blocks allocated */
long st_blksize; /* optimal I/O block size */
}

Relevant ls(1) flags: '-c', '-t', '-u'


2
Jan Schaumann 2020-09-26
CS631 - Advanced Programming in the UNIX Environment

atime, mtime, ctime


mtime

3
Jan Schaumann 2020-09-26
CS631 - Advanced Programming in the UNIX Environment

atime, mtime, ctime

atime

4
Jan Schaumann 2020-09-26
CS631 - Advanced Programming in the UNIX Environment

atime, mtime, ctime

ctime

5
Jan Schaumann 2020-09-26
CS631 - Advanced Programming in the UNIX Environment

atime, mtime, ctime

6
Jan Schaumann 2020-09-26
CS631 - Advanced Programming in the UNIX Environment

atime, mtime, ctime

7
Jan Schaumann 2020-09-26
CS631 - Advanced Programming in the UNIX Environment

atime, mtime, ctime

8
Jan Schaumann 2020-09-26
CS631 - Advanced Programming in the UNIX Environment

atime, mtime, ctime

9
Jan Schaumann 2020-09-26
CS631 - Advanced Programming in the UNIX Environment

atime, mtime, ctime

10
Jan Schaumann 2020-09-26
CS631 - Advanced Programming in the UNIX Environment

atime, mtime, ctime

11
Jan Schaumann 2020-09-26
CS631 - Advanced Programming in the UNIX Environment

atime, mtime, ctime

12
Jan Schaumann 2020-09-26
CS631 - Advanced Programming in the UNIX Environment

atime, mtime, ctime

13
Jan Schaumann 2020-09-26
CS631 - Advanced Programming in the UNIX Environment

atime, mtime, ctime

14
Jan Schaumann 2020-09-26
CS631 - Advanced Programming in the UNIX Environment

atime, mtime, ctime

15
Jan Schaumann 2020-09-26
CS631 - Advanced Programming in the UNIX Environment

atime, mtime, ctime

16
Jan Schaumann 2020-09-26
CS631 - Advanced Programming in the UNIX Environment

atime, mtime, ctime

17
Jan Schaumann 2020-09-26
CS631 - Advanced Programming in the UNIX Environment

atime, mtime, ctime

18
Jan Schaumann 2020-09-26
CS631 - Advanced Programming in the UNIX Environment

atime, mtime, ctime

19
Jan Schaumann 2020-09-26
CS631 - Advanced Programming in the UNIX Environment

atime, mtime, ctime

20
Jan Schaumann 2020-09-26
CS631 - Advanced Programming in the UNIX Environment

atime, mtime, ctime

21
Jan Schaumann 2020-09-26
CS631 - Advanced Programming in the UNIX Environment

atime, mtime, ctime

22
Jan Schaumann 2020-09-26
CS631 - Advanced Programming in the UNIX Environment

atime, mtime, ctime

23
Jan Schaumann 2020-09-26
CS631 - Advanced Programming in the UNIX Environment

atime, mtime, ctime

24
Jan Schaumann 2020-09-26
CS631 - Advanced Programming in the UNIX Environment

atime, mtime, ctime

25
Jan Schaumann 2020-09-26
CS631 - Advanced Programming in the UNIX Environment

atime, mtime, ctime

26
Jan Schaumann 2020-09-26
CS631 - Advanced Programming in the UNIX Environment

atime, mtime, ctime

27
Jan Schaumann 2020-09-26
CS631 - Advanced Programming in the UNIX Environment

utimes(2)
#include <sys/time.h>

int utimes(const char *path, const struct timeval times[2]);


int lutimes(const char *path, const struct timeval times[2]);
int futimes(int fd, const struct timeval times[2]);
int utimensat(int fd, const char *path, const struct timespec times[2], int flag);
Returns: 0 if OK, -1 on error

• if times is NULL, set atime and mtime to current time (write permissions sufficient)
• if times is non-NULL, set atime and mtime accordingly (need to be owner)
• either way, ctime is set to current time
• timespec allows for nanosecond precision
28
Jan Schaumann 2020-09-26
CS631 - Advanced Programming in the UNIX Environment

atime, mtime, ctime


• atime: time of last data access
• may trigger frequent I/O; diminishes performance
• remedies: mount -o noatime, nodiratime, relatime, lazytime
• mtime: time of last data modification
• ctime: time of last file status change; automatically updated by various syscalls
• utimes(2) with values requires ownership; may update non-standard time fields
• you can now implement touch(1)

Time is weird. We'll get into more on that next time.

29
Jan Schaumann 2020-09-26
CS631 - Advanced Programming in the UNIX Environment

Links and Discussions


• POSIX: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/
V1_chap04.html#tag_04_09
• https://en.wikipedia.org/wiki/Stat_%28system_call%29#Criticism_of_atime
• Once upon atime: https://lwn.net/Articles/244829/

30
Jan Schaumann 2020-09-26

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy