TIMES(3P)
β¨ TIMES(3P) β¨
okay bestie, welcome to the POSIX Programmer's Manual π you're in the TIMES(3P) section, and we're about to get into how your process keeps receipts on its own CPU time. slay.
π«Ά PROLOG
so like, this manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (peep the corresponding Linux manual page for the tea on Linux behavior), or honestly the interface might not even be implemented on Linux at all. no cap. π
πΈ NAME
times β get process and waited-for child process times π
π SYNOPSIS
#include <sys/times.h>
clock_t times(struct tms *buffer);
π DESCRIPTION
okay so times() shall fill the tms structure pointed to by buffer with time-accounting information. The tms structure is defined in <sys/times.h>. periodt.
All times are measured in terms of the number of clock ticks used. that's the unit, bestie, don't forget it β¨
The times of a terminated child process shall be included in the tms_cutime and tms_cstime elements of the parent when wait(), waitid(), or waitpid() returns the process ID of this terminated child. But β and this is the plot twist β if a child process has not waited for its children, their times shall not be included in its times. π
- The
tms_utimestructure member is the CPU time charged for the execution of user instructions of the calling process. that's your process doing its lil user-space thing π - The
tms_stimestructure member is the CPU time charged for execution by the system on behalf of the calling process. the kernel doing stuff for you, basically π§ - The
tms_cutimestructure member is the sum of thetms_utimeandtms_cutimetimes of the child processes. yes the same name twice, that's not a typo, that's literally what it says π - The
tms_cstimestructure member is the sum of thetms_stimeandtms_cstimetimes of the child processes.
β RETURN VALUE
Upon successful completion, times() shall return the elapsed real time, in clock ticks, since an arbitrary point in the past (for example, system start-up time). That point does not change from one invocation of times() within the process to another. iconic behavior honestly π
β οΈ the return value may overflow the possible range of type clock_t. be aware bestie π
If times() fails, (clock_t)-1 shall be returned and errno set to indicate the error.
π₯ ERRORS
The times() function shall fail if:
EOVERFLOWβ The return value would overflow the range ofclock_t.
The following sections are informative. (translation: the vibe shifts from "rules" to "chat" π«Ά)
π EXAMPLES
Timing a Database Lookup
The following example defines two functions, start_clock() and end_clock(), that are used to time a lookup. It also defines variables of type clock_t and tms to measure the duration of transactions. The start_clock() function saves the beginning times given by the times() function. The end_clock() function gets the ending times and prints the difference between the two times.
#include <sys/times.h>
#include <stdio.h>
...
void start_clock(void);
void end_clock(char *msg);
...
static clock_t st_time;
static clock_t en_time;
static struct tms st_cpu;
static struct tms en_cpu;
...
void
start_clock()
{
st_time = times(&st_cpu);
}
/* This example assumes that the result of each subtraction
is within the range of values that can be represented in
an integer type. */
void
end_clock(char *msg)
{
en_time = times(&en_cpu);
fputs(msg,stdout);
printf("Real Time: %jd, User Time %jd, System Time %jd\n",
(intmax_t)(en_time - st_time),
(intmax_t)(en_cpu.tms_utime - st_cpu.tms_utime),
(intmax_t)(en_cpu.tms_stime - st_cpu.tms_stime));
}
π APPLICATION USAGE
Applications should use sysconf(_SC_CLK_TCK) to determine the number of clock ticks per second, as it may vary from system to system. don't hardcode it bestie, that's a trap πͺ€
π¦ RATIONALE
The accuracy of the times reported is intentionally left unspecified to allow implementations flexibility in design, from uniprocessor to multi-processor networks. it's giving "we're not gonna commit to a number" π
The inclusion of times of child processes is recursive, so that a parent process may collect the total times of all of its descendants. But the times of a child are only added to those of its parent when its parent successfully waits on the child. Thus, it is not guaranteed that a parent process can always see the total times of all its descendants; see also the discussion of the term ``realtime'' in alarm().
If the type clock_t is defined to be a signed 32-bit integer, it overflows in somewhat more than a year if there are 60 clock ticks per second, or less than a year if there are 100. There are individual systems that run continuously for longer than that. This volume of POSIX.1β2017 permits an implementation to make the reference point for the returned value be the start-up time of the process, rather than system start-up time. π (long uptime girlies, stay safe)
The term ``charge'' in this context has nothing to do with billing for services. The operating system accounts for time used in this way. That information must be correct, regardless of how that information is used. no invoices here, just accounting β¨
π FUTURE DIRECTIONS
None. we love a calm future π«Ά
π SEE ALSO
alarm(), exec, fork(), sysconf(), time(), wait(), waitid()
The Base Definitions volume of POSIX.1β2017, <sys_times.h>
π COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
and that's the whole page bestie π this one came to you from IEEE/The Open Group, 2017 β TIMES(3P), that's the page, that's the date, we're done. slay, go time some processes πβ¨
π¦ where this page comes from
- alpine 3.22: man-pages-posix 2017a-r0 Β· custom
- alpine 3.23: man-pages-posix 2017a-r0 Β· custom
- alpine 3.24: man-pages-posix 2017a-r0 Β· custom
- arch rolling: man-pages 6.19-1
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages-posix 2017a
- opensuse-leap 16.0: man-pages-posix 2017a-160000.4.1 Β· SUSE-IEEE
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms