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 the tms_utime and tms_cutime values 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 the tms_stime and tms_cstime values 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 โ€” tms points 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-NULL value for buf. 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-1996 the symbol CLK_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 SIGCHLD is set to SIG_IGN, then the times of terminated children are automatically included in the tms_cstime and tms_cutime fields โ€” although POSIX.1-2001 says that this should happen only if the calling process wait(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) - 300 seconds 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-3 returns long and the struct members are of type time_t โ€” although they store clock ticks, not seconds since the Epoch. sneaky. misleading. iconic in a bad way ๐Ÿ’…. and V7 used long for the struct members, because it had no type time_t yet. 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
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms