1TIMES(2) Linux Programmer's Manual TIMES(2)
2
3
4
6 times - get process times
7
9 #include <sys/times.h>
10
11 clock_t times(struct tms *buf);
12
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
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 er‐
45 rno is set to indicate the error.
46
48 EFAULT tms points outside the process's address space.
49
51 POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD.
52
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 b