1times(2)                      System Calls Manual                     times(2)
2
3
4

NAME

6       times - get process times
7

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

12       #include <sys/times.h>
13
14       clock_t times(struct tms *buf);
15

DESCRIPTION

17       times()  stores  the  current  process times in the struct tms that buf
18       points to.  The struct tms is as defined in <sys/times.h>:
19
20           struct tms {
21               clock_t tms_utime;  /* user time */
22               clock_t tms_stime;  /* system time */
23               clock_t tms_cutime; /* user time of children */
24               clock_t tms_cstime; /* system time of children */
25           };
26
27       The tms_utime field contains the CPU time spent executing  instructions
28       of  the  calling  process.   The  tms_stime field contains the CPU time
29       spent executing inside the kernel while performing tasks on  behalf  of
30       the calling process.
31
32       The  tms_cutime  field contains the sum of the tms_utime and tms_cutime
33       values for all waited-for terminated children.   The  tms_cstime  field
34       contains the sum of the tms_stime and tms_cstime values for all waited-
35       for terminated children.
36
37       Times for terminated children (and their descendants) are added  in  at
38       the moment wait(2) or waitpid(2) returns their process ID.  In particu‐
39       lar, times of grandchildren that the children  did  not  wait  for  are
40       never seen.
41
42       All times reported are in clock ticks.
43

RETURN VALUE

45       times()  returns  the  number of clock ticks that have elapsed since an
46       arbitrary point in the past.  The return value may overflow the  possi‐
47       ble range of type clock_t.  On error, (clock_t) -1 is returned, and er‐
48       rno is set to indicate the error.
49

ERRORS

51       EFAULT tms points outside the process's address space.
52

VERSIONS

54       On Linux, the buf argument can be specified as NULL,  with  the  result
55       that  times()  just returns a function result.  However, POSIX does not
56       specify this behavior, and most other UNIX  implementations  require  a
57       non-NULL value for buf.
58

STANDARDS

60       POSIX.1-2008.
61

HISTORY

63       POSIX.1-2001, SVr4, 4.3BSD.
64
65       In  POSIX.1-1996  the symbol CLK_TCK (defined in <time.h>) is mentioned
66       as obsolescent.  It is obsolete now.
67
68       Before Linux 2.6.9, if the disposition of SIGCHLD is  set  to  SIG_IGN,
69       then the times of terminated children are automatically included in the
70       tms_cstime and tms_cutime fields, although POSIX.1-2001 says that  this
71       should  happen  only  if  the calling process wait(2)s on its children.
72       This nonconformance is rectified in Linux 2.6.9 and later.
73
74       On Linux, the “arbitrary point in the past” from which the return value
75       of times() is measured has varied across kernel versions.  On Linux 2.4
76       and earlier, this point is the moment the  system  was  booted.   Since
77       Linux  2.6,  this  point  is (2^32/HZ) - 300 seconds before system boot
78       time.  This variability across kernel versions (and across UNIX  imple‐
79       mentations),  combined  with the fact that the returned value may over‐
80       flow the range of clock_t, means that a portable application  would  be
81       wise  to  avoid  using this value.  To measure changes in elapsed time,
82       use clock_gettime(2) instead.
83
84       SVr1-3 returns long and the struct members are of type time_t  although
85       they  store clock ticks, not seconds since the Epoch.  V7 used long for
86       the struct members, because it had no type time_t yet.
87

NOTES

89       The number of clock ticks per second can be obtained using:
90
91           sysconf(_SC_CLK_TCK);
92
93       Note that clock(3) also returns a value of type clock_t, but this value
94       is  measured  in  units  of CLOCKS_PER_SEC, not the clock ticks used by
95       times().
96

BUGS

98       A limitation of the Linux system call conventions on some architectures
99       (notably i386) means that on Linux 2.6 there is a small time window (41
100       seconds) soon after boot when times() can return -1, falsely indicating
101       that  an  error  occurred.   The same problem can occur when the return
102       value wraps past the maximum value that can be stored in clock_t.
103

SEE ALSO

105       time(1), getrusage(2), wait(2), clock(3), sysconf(3), time(7)
106
107
108
109Linux man-pages 6.04              2023-03-30                          times(2)
Impressum