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

CONFORMING TO

46       SVr4, 4.3BSD, POSIX.1-2001.
47

NOTES

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

BUGS

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

SEE ALSO

95       time(1), getrusage(2), wait(2), clock(3), sysconf(3), time(7)
96

COLOPHON

98       This  page  is  part of release 3.25 of the Linux man-pages project.  A
99       description of the project, and information about reporting  bugs,  can
100       be found at http://www.kernel.org/doc/man-pages/.
101
102
103
104Linux                             2008-06-25                          TIMES(2)
Impressum