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) is  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.  For Linux 2.4 and earlier this  point  is
42       the  moment  the  system  was  booted.   Since Linux 2.6, this point is
43       (2^32/HZ) - 300 (i.e., about 429 million) seconds  before  system  boot
44       time.   The  return  value  may  overflow  the  possible  range of type
45       clock_t.  On error, (clock_t) -1 is returned, and errno is  set  appro‐
46       priately.
47

NOTES

49       The number of clock ticks per second can be obtained using
50              sysconf(_SC_CLK_TCK);
51       In  POSIX-1996 the symbol CLK_TCK (defined in <time.h>) is mentioned as
52       obsolescent. It is obsolete now.
53
54       In Linux kernel versions before 2.6.9, if the disposition of SIGCHLD is
55       set  to SIG_IGN then the times of terminated children are automatically
56       included in the tms_cstime and tms_cutime fields, although POSIX.1-2001
57       says that this should only happen if the calling process wait()s on its
58       children.  This non-conformance is rectified in Linux 2.6.9 and later.
59
60       On Linux, the buf argument can be specified as NULL,  with  the  result
61       that  times()  just returns a function result.  However, POSIX does not
62       specify this behaviour, and most other Unix implementations  require  a
63       non-NULL value for buf.
64
65       Note that clock(3) returns values of type clock_t that are not measured
66       in clock ticks but in CLOCKS_PER_SEC.
67

CONFORMING TO

69       SVr4, 4.3BSD, POSIX.1-2001.
70

HISTORICAL NOTES

72       SVr1-3 returns long and the struct members are of type time_t  although
73       they  store clock ticks, not seconds since the epoch.  V7 used long for
74       the struct members, because it had no type time_t yet.
75
76       On older systems the number of clock ticks per second is given  by  the
77       variable HZ.
78

SEE ALSO

80       time(1), getrusage(2), wait(2), clock(3), sysconf(3), time(7)
81
82
83
84Linux                             2002-06-14                          TIMES(2)
Impressum