1TIMES(2)                   Linux Programmer's Manual                  TIMES(2)
2
3
4

NAME

6       times - get process times
7

SYNOPSIS

9       #include <sys/times.h>
10
11       clock_t times(struct tms *buf);
12

DESCRIPTION

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

RETURN VALUE

42       times()  returns  the  number of clock ticks that have elapsed since an
43       arbitrary point in the past.  The return value may overflow the  possi‐
44       ble  range  of  type  clock_t.  On error, (clock_t) -1 is returned, and
45       errno is set appropriately.
46

ERRORS

48       EFAULT tms points outside the process's address space.
49

CONFORMING TO

51       POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD.
52

NOTES

54       The number of clock ticks per second can be obtained using:
55
56           sysconf(_SC_CLK_TCK);
57
58       In POSIX.1-1996 the symbol CLK_TCK (defined in <time.h>)  is  mentioned
59       as obsolescent.  It is obsolete now.
60
61       In Linux kernel versions before 2.6.9, if the disposition of SIGCHLD is
62       set to SIG_IGN, then the times of terminated children are automatically
63       included in the tms_cstime and tms_cutime fields, although POSIX.1-2001
64       says that this should happen only if the calling  process  wait(2)s  on
65       its  children.   This  nonconformance  is  rectified in Linux 2.6.9 and
66       later.
67
68       On Linux, the buf argument can be specified as NULL,  with  the  result
69       that  times()  just returns a function result.  However, POSIX does not
70       specify this behavior, and most other UNIX  implementations  require  a
71       non-NULL value for buf.
72
73       Note that clock(3) also returns a value of type clock_t, but this value
74       is measured in units of CLOCKS_PER_SEC, not the  clock  ticks  used  by
75       times().
76
77       On Linux, the "arbitrary point in the past" from which the return value
78       of times() is measured has varied across kernel versions.  On Linux 2.4
79       and  earlier,  this  point  is the moment the system was booted.  Since
80       Linux 2.6, this point is (2^32/HZ) - 300  seconds  before  system  boot
81       time.   This variability across kernel versions (and across UNIX imple‐
82       mentations), combined with the fact that the returned value  may  over‐
83       flow  the  range of clock_t, means that a portable application would be
84       wise to avoid using this value.  To measure changes  in  elapsed  time,
85       use clock_gettime(2) instead.
86
87   Historical
88       SVr1-3  returns long and the struct members are of type time_t although
89       they store clock ticks, not seconds since the Epoch.  V7 used long  for
90       the struct members, because it had no type time_t yet.
91

BUGS

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

SEE ALSO

100       time(1), getrusage(2), wait(2), clock(3), sysconf(3), time(7)
101

COLOPHON

103       This  page  is  part of release 4.16 of the Linux man-pages project.  A
104       description of the project, information about reporting bugs,  and  the
105       latest     version     of     this    page,    can    be    found    at
106       https://www.kernel.org/doc/man-pages/.
107
108
109
110Linux                             2017-09-15                          TIMES(2)
Impressum