times(2)
โจ times(2) โ the process-times girlies' manual page โจ
okay so bestie, you're reading the times(2) page from the System Calls Manual, and honestly? it's giving clock ticks and childhood trauma (the child-process kind, don't worry ๐ซถ). let's get into it.
๐ธ NAME ๐ธ
times โ get process times โฐ
๐ LIBRARY ๐
Standard C library (libc, -lc) โ yes the classic, she's iconic, she's everywhere ๐
๐ฆ SYNOPSIS ๐ฆ
#include <sys/times.h>
clock_t times(struct tms *buf);
๐ DESCRIPTION ๐
so like, times() stores the current process times in the struct tms that buf points to. no cap. and struct tms is defined in <sys/times.h> like this:
struct tms {
clock_t tms_utime; /* user time */
clock_t tms_stime; /* system time */
clock_t tms_cutime; /* user time of children */
clock_t tms_cstime; /* system time of children */
};
let's break those fields down because each one is a lil main character:
tms_utimeโ the CPU time spent executing instructions of the calling process. that's you, bestie. your actual work. your moment. ๐tms_stimeโ the CPU time spent executing inside the kernel while performing tasks on behalf of the calling process. the unpaid invisible labor, honestly ๐ญtms_cutimeโ the sum of thetms_utimeandtms_cutimevalues for all waited-for terminated children. yes it says both names, that's not a typo, that's literally what the page says, write it down ๐tms_cstimeโ the sum of thetms_stimeandtms_cstimevalues for all waited-for terminated children.
the way times for terminated children (and their descendants, the whole extended family ๐) get added in at the exact moment wait(2) or waitpid(2) returns their process ID. so precise. so specific.
๐ BUT here's the tea: times of grandchildren that the children did not wait for are never seen. if your kid didn't wait for their kid, that data is simply not invited to the function. periodt.
and also โ every single time reported here is in clock ticks. not seconds. ticks. iykyk.
๐ RETURN VALUE ๐
times() returns the number of clock ticks that have elapsed since an arbitrary point in the past. like, mysterious. no one knows exactly when. very mysterious-future-mystery-vibe.
and listen โ that return value may overflow the possible range of type clock_t. it's giving "we didn't measure, we vibed".
on error, (clock_t) -1 is returned, and errno is set to indicate the error. classic.
๐ ERRORS ๐
EFAULTโtmspoints outside the process's address space. like girl, that pointer is NOT yours, get out of there ๐ญ
๐ง VERSIONS ๐ง
on Linux, the buf argument can be specified as NULL, and the result is that times() just returns a function result. slay, low effort, we love that for her.
โ ๏ธ HOWEVER โ POSIX does not specify this behavior, and most other UNIX implementations require a non-NULLvalue forbuf. so if you're being portable, don't do the cute shortcut. ๐
๐ STANDARDS ๐
POSIX.1-2024. certified. official. ๐
๐ HISTORY ๐
POSIX.1-2001,SVr4,4.3BSD. the whole lineage, the whole family tree ๐ธ- in
POSIX.1-1996the symbolCLK_TCK(defined in<time.h>) is mentioned as obsolescent. it is obsolete now. she's retired. gone. we don't talk about her ๐ - before Linux 2.6.9, if the disposition of
SIGCHLDis set toSIG_IGN, then the times of terminated children are automatically included in thetms_cstimeandtms_cutimefields โ althoughPOSIX.1-2001says that this should happen only if the calling processwait(2)s on its children. this nonconformance is rectified in Linux 2.6.9 and later. glow up achieved โจ - on Linux, the "arbitrary point in the past" from which the return value of
times()is measured has varied across kernel versions. not consistent, not loyal, we've moved on ๐ซ- on Linux 2.4 and earlier, this point is the moment the system was booted.
- since Linux 2.6, this point is
(2^32/HZ) - 300seconds before system boot time.
this variability across kernel versions (and across UNIX implementations), combined with the fact that the returned value may overflow the range of clock_t, means that a portable application would be wise to avoid using this value. like... just don't. ๐ฉ
๐ก to measure changes in elapsed time, use clock_gettime(2) instead. that's the actual recommendation, bestie, take it.
SVr1-3returnslongand the struct members are of typetime_tโ although they store clock ticks, not seconds since the Epoch. sneaky. misleading. iconic in a bad way ๐ . andV7usedlongfor the struct members, because it had no typetime_tyet. baby steps, we've all been there ๐
๐ NOTES ๐
the number of clock ticks per second can be obtained using:
sysconf(_SC_CLK_TCK);
and just so you're not confused out there in these streets โ note that clock(3) also returns a value of type clock_t, but that value is measured in units of CLOCKS_PER_SEC, not the clock ticks used by times(). two different girls, two different units. don't mix them up ๐
๐ฅ BUGS ๐ฅ
okay so this one's important, bestie, pay attention:
a limitation of the Linux system call conventions on some architectures (notably i386) means that on Linux 2.6 there is a small time window (41 seconds) soon after boot when times() can return -1, falsely indicating that an error occurred. ๐ญ a liar! a scammer!
the same problem can occur when the return value wraps past the maximum value that can be stored in clock_t. so like, watch out for that. ๐
๐ SEE ALSO ๐
time(1), getrusage(2), wait(2), clock(3), sysconf(3), time(7)
and that's the whole page, babe ๐ซถ this was Linux man-pages 6.20, dated 2026-02-08, and yes, the times(2) page really did all that. go measure some elapsed time with clock_gettime(2) instead, love u, bye ๐โจ
๐ฆ where this page comes from
- 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 6.20
- ๐ the page's license: Linux-man-pages-copyleft
- Copyright 1992, Drew Eckhardt <drew@cs.colorado.edu>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms