1TIMES(3P)                  POSIX Programmer's Manual                 TIMES(3P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10

NAME

12       times — get process and waited-for child process times
13

SYNOPSIS

15       #include <sys/times.h>
16
17       clock_t times(struct tms *buffer);
18

DESCRIPTION

20       The times() function shall fill the tms structure pointed to by  buffer
21       with  time-accounting  information.  The  tms  structure  is defined in
22       <sys/times.h>.
23
24       All times are measured in terms of the number of clock ticks used.
25
26       The times of a terminated  child  process  shall  be  included  in  the
27       tms_cutime and tms_cstime elements of the parent when wait(), waitid(),
28       or waitpid() returns the process ID of  this  terminated  child.  If  a
29       child process has not waited for its children, their times shall not be
30       included in its times.
31
32        *  The tms_utime structure member is the CPU time charged for the exe‐
33           cution of user instructions of the calling process.
34
35        *  The  tms_stime  structure member is the CPU time charged for execu‐
36           tion by the system on behalf of the calling process.
37
38        *  The tms_cutime structure member is the sum  of  the  tms_utime  and
39           tms_cutime times of the child processes.
40
41        *  The  tms_cstime  structure  member  is the sum of the tms_stime and
42           tms_cstime times of the child processes.
43

RETURN VALUE

45       Upon successful completion, times() shall return the elapsed real time,
46       in clock ticks, since an arbitrary point in the past (for example, sys‐
47       tem start-up time). This point does not change from one  invocation  of
48       times()  within  the  process to another. The return value may overflow
49       the possible range of type  clock_t.   If  times()  fails,  (clock_t)-1
50       shall be returned and errno set to indicate the error.
51

ERRORS

53       The times() function shall fail if:
54
55       EOVERFLOW
56              The return value would overflow the range of clock_t.
57
58       The following sections are informative.
59

EXAMPLES

61   Timing a Database Lookup
62       The   following   example  defines  two  functions,  start_clock()  and
63       end_clock(), that are used to time a lookup. It also defines  variables
64       of  type  clock_t  and tms to measure the duration of transactions. The
65       start_clock() function saves the beginning times given by  the  times()
66       function. The end_clock() function gets the ending times and prints the
67       difference between the two times.
68
69
70           #include <sys/times.h>
71           #include <stdio.h>
72           ...
73           void start_clock(void);
74           void end_clock(char *msg);
75           ...
76           static clock_t st_time;
77           static clock_t en_time;
78           static struct tms st_cpu;
79           static struct tms en_cpu;
80           ...
81           void
82           start_clock()
83           {
84               st_time = times(&st_cpu);
85           }
86
87           /* This example assumes that the result of each subtraction
88              is within the range of values that can be represented in
89              an integer type. */
90           void
91           end_clock(char *msg)
92           {
93               en_time = times(&en_cpu);
94
95               fputs(msg,stdout);
96               printf("Real Time: %jd, User Time %jd, System Time %jd\n",
97                   (intmax_t)(en_time - st_time),
98                   (intmax_t)(en_cpu.tms_utime - st_cpu.tms_utime),
99                   (intmax_t)(en_cpu.tms_stime - st_cpu.tms_stime));
100           }
101

APPLICATION USAGE

103       Applications should use sysconf(_SC_CLK_TCK) to determine the number of
104       clock ticks per second as it may vary from system to system.
105

RATIONALE

107       The accuracy of the times reported is intentionally left unspecified to
108       allow implementations  flexibility  in  design,  from  uniprocessor  to
109       multi-processor networks.
110
111       The  inclusion of times of child processes is recursive, so that a par‐
112       ent process may collect the total times of all of its descendants.  But
113       the  times  of  a  child are only added to those of its parent when its
114       parent successfully waits on the child. Thus, it is not guaranteed that
115       a parent process can always see the total times of all its descendants;
116       see also the discussion of the term ``realtime'' in alarm().
117
118       If the type clock_t is defined to be a signed 32-bit integer, it  over‐
119       flows in somewhat more than a year if there are 60 clock ticks per sec‐
120       ond, or less than a year if there are 100. There are individual systems
121       that run continuously for longer than that. This volume of POSIX.1‐2017
122       permits an implementation to make the reference point for the  returned
123       value  be the start-up time of the process, rather than system start-up
124       time.
125
126       The term ``charge'' in this context has nothing to do with billing  for
127       services. The operating system accounts for time used in this way. That
128       information must be correct, regardless  of  how  that  information  is
129       used.
130

FUTURE DIRECTIONS

132       None.
133

SEE ALSO

135       alarm(), exec, fork(), sysconf(), time(), wait(), waitid()
136
137       The Base Definitions volume of POSIX.1‐2017, <sys_times.h>
138
140       Portions  of  this text are reprinted and reproduced in electronic form
141       from IEEE Std 1003.1-2017, Standard for Information Technology --  Por‐
142       table  Operating System Interface (POSIX), The Open Group Base Specifi‐
143       cations Issue 7, 2018 Edition, Copyright (C) 2018 by the  Institute  of
144       Electrical  and  Electronics Engineers, Inc and The Open Group.  In the
145       event of any discrepancy between this version and the original IEEE and
146       The  Open Group Standard, the original IEEE and The Open Group Standard
147       is the referee document. The original Standard can be  obtained  online
148       at http://www.opengroup.org/unix/online.html .
149
150       Any  typographical  or  formatting  errors that appear in this page are
151       most likely to have been introduced during the conversion of the source
152       files  to  man page format. To report such errors, see https://www.ker
153       nel.org/doc/man-pages/reporting_bugs.html .
154
155
156
157IEEE/The Open Group                  2017                            TIMES(3P)
Impressum