Class 22 - Linux Timers
Time Values
  1. elapsed time
    1. calendar time
    2. processor time
  2. interval time
    1. some timers provided in hardware
    2. operating system software implements additional timers

Calendar time counts the number of seconds since the Epoch, 00:00:00 January 1, 1970 Coordinated Universal Time (UTC). This is used by the operating system for tasks such as determining which a file was last used.

Processor time is cpu time. It is used by the operating system to measure resource usage. Processor time is measured in clock ticks.

Using time at the command line yields a combination of these. 90.7u 12.9s 2:39 65% means

90.7 seconds user cpu time
12.9 seconds system cpu time
2:39 seconds elapsed time
65% of the elapsed time was cpu time
call protocol example time value
time() #include <time.h>
time_t time(time_t *calptr);
real time (wall clock)

also stores time value in place pointed to by calptr
gmtime() #include <time.h>
struct tm *gmtime(const time_t *calptr);
from real time to broken down time
mktime() #include <time.h>
time_t mktime( struct tm *tmptr);
from broken down time to real time
localtime() #include <time.h>
struct tm *localtime(const time_t *calptr);
from real time to broken down time
ctime() #include <time.h>
char *ctime(const time_t *clock);
from real time to ascii real time (wall clock)
returned in 26-character buffer
damo dat hr : min : secyear \n \0
3 1 3 1 2 1 2 1 2 1 2 1 4 1 1
asctime() #include <time.h>
char *asctime(const struct tm *tmptr);
from broken down time to ascii real time
strftime() #include <time.h>
size_t strftime(char *buf, size_t maxsize, const char *format, const struct tm *tmptr);
from broken down time to formatted string
times() #include <sys/times.h>
clock_t times (struct tms *buffer);
example 6.1 from broken down time to virtual time (time in run state)
returns info about process and its children in struct tms
gettimeofday()#include <sys/times.h>
int gettimeofday (struct timeval *tp, void *tzp);
example 6.2 real time with greater accuracy
clock_setitimer() #include <sys/times.h>
int clock_setitimer(int which, const struct itimerval *value, struct itimeval *ovalue);
program 6.1 interval timer for user - set it
clock_getitimer() #include <sys/times.h>
int clock_getitimer(int which, struct itimerval *value);
program 6.2 interval timer for user - get the time remaining

name manpage
section
purpose
adjtimex (2) - tune kernel clock
asctime [ctime] (3) - transform binary date and time to ASCII
clock (3) - Determine processor time
clockdiff (8) - Measures clock difference between us and destination with 1msec resolution.
Without -o option it uses icmp timestamps, with -o it uses icmp echo with timestamp IP option
ctime (3) - transform binary date and time to ASCII
date (1) - print or set the system date and time
difftime (3) - calculate time difference
ftime (3) - return date and time
getitimer (2) - get or set value of an interval timer
gettimeofday (2) - get / set time
gmtime [ctime] (3) - transform binary date and time to ASCII
gtt (1) - GTimeTracker - a time tracker
localtime [ctime] (3) - transform binary date and time to ASCII
mktime [ctime] (3) - transform binary date and time to ASCII
nanosleep (2) - pause execution for a specified time
newer (1) - compare file modification times
profil (3) - execution time profile
rdate (1) - get the time via the network
ruptime (1) - show host status of local machines
setitimer [getitimer] (2) - get or set value of an interval timer
settimeofday [gettimeofday] (2) - get / set time
sleep (1) - delay for a specified amount of time
stime (2) - set time
strftime (3) - format date and time
strptime (3) - convert a string representation of time
to a time tm structure
sysconf (3) - Get configuration information at runtime
sysctl (8) - configure kernel parameters at runtime
time (2) - get time in seconds
timeconfig (8) - simple interface for configuring system time parameters
timed (8) - time server daemon
timedc (8) - timed control program
times (2) - get process times
times [builtins2] (1) - bash built-in commands, see bash(1)
tzfile (5) - time zone information
tzselect (8) - select a time zone
tzset (3) - initialize time conversion information
uptime (1) - Tell how long the system has been running
t3d (1) - clock using flying balls to display the time
Benchmark (3) - benchmark running times of code
Time::Local (3) - efficiently compute time from local and GMT time
Time::gmtime (3) - by-name interface to Perl's built-in gmtime() function
Time::localtime (3) - by-name interface to Perl's built-in localtime() function
Time::tm (3) - internal object used by Time::gmtime and Time::localtime
timeit [Benchmark] (3) - run a chunk of code and see how long it goes
timethese [Benchmark] (3) - run several chunks of code several times
timethis [Benchmark] (3) - run a chunk of code several times

Manpage sections are

  1. user commands
  2. system calls
  3. C library functions
  4. devices and network interfaces
  5. file formats
  6. games and demos
  7. environments, tables, troff macros

Lab 22