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 in the system while executing tasks  on  behalf  of  the  calling
27       process.   The  tms_cutime  field contains the sum of the tms_utime and
28       tms_cutime  values  for  all  waited-for  terminated   children.    The
29       tms_cstime  field contains the sum of the tms_stime and tms_cstime val‐
30       ues for all waited-for terminated children.
31
32       Times for terminated children (and their descendants) are added  in  at
33       the moment wait(2) or waitpid(2) returns their process ID.  In particu‐
34       lar, times of grandchildren that the children  did  not  wait  for  are
35       never seen.
36
37       All times reported are in clock ticks.
38

RETURN VALUE

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

ERRORS

46       EFAULT tms points outside the process's address space.
47

CONFORMING TO

49       SVr4, 4.3BSD, POSIX.1-2001.
50

NOTES

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

BUGS

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

SEE ALSO

98       time(1), getrusage(2), wait(2), clock(3), sysconf(3), time(7)
99

COLOPHON

101       This  page  is  part of release 3.53 of the Linux man-pages project.  A
102       description of the project, and information about reporting  bugs,  can
103       be found at http://www.kernel.org/doc/man-pages/.
104
105
106
107Linux                             2012-10-22                          TIMES(2)
Impressum