GETRUSAGE(2)
π getrusage(2) β the resource utilization tea π
okay bestie, so this is a System Calls Manual page, section 2, and it's literally all about getrusage β the little syscall that tells you what your processes have been consuming. peak main character energy fr fr.
β¨ NAME β¨
getrusage β get information about resource utilization
π LIBRARY π
Standard C Library (libc, -lc)
π SYNOPSIS π
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#define RUSAGE_SELF 0
#define RUSAGE_CHILDREN -1
#define RUSAGE_THREAD 1
int
getrusage(int who, struct rusage *rusage);
π¦ DESCRIPTION π¦
So the getrusage() system call hands you back the deets on the resources that have been used up by the current thread, the current process, or all of its terminated child processes. slay.
The who argument is one of RUSAGE_THREAD, RUSAGE_SELF, or RUSAGE_CHILDREN β pick your fighter π
And the buffer that rusage points at gets filled in with this exact structure, no cap:
struct rusage {
struct timeval ru_utime; /* user time used */
struct timeval ru_stime; /* system time used */
long ru_maxrss; /* max resident set size */
long ru_ixrss; /* integral shared text memory size */
long ru_idrss; /* integral unshared data size */
long ru_isrss; /* integral unshared stack size */
long ru_minflt; /* page reclaims */
long ru_majflt; /* page faults */
long ru_nswap; /* swaps */
long ru_inblock; /* block input operations */
long ru_oublock; /* block output operations */
long ru_msgsnd; /* messages sent */
long ru_msgrcv; /* messages received */
long ru_nsignals; /* signals received */
long ru_nvcsw; /* voluntary context switches */
long ru_nivcsw; /* involuntary context switches */
};
okay now let's read the fields, because each one is giving something different:
ru_utimeβ the total amount of time spent executing in user mode. that's the fun part, the actual doing stuff time β¨ru_stimeβ the total amount of time spent in the system executing on behalf of the process(es). the kernel's doing your bidding, respectfully πru_maxrssβ the maximum resident set size utilized, in kilobytes.ru_ixrssβ an βintegralβ value showing how much memory was used by the text segment that was also shared among other processes. this one's expressed in units of kilobytes * ticks-of-execution. and what's a tick? ticks are statistics clock ticks. the statistics clock has a frequency ofsysconf(_SC_CLK_TCK)ticks per second. iykyk π§ru_idrssβ an integral value of the amount of unshared memory chillin' in the data segment of a process, expressed in units of kilobytes * ticks-of-execution.ru_isrssβ an integral value of the amount of unshared memory chillin' in the stack segment of a process, expressed in units of kilobytes * ticks-of-execution.ru_minfltβ the number of page faults serviced without any I/O activity. here, I/O activity gets avoided by βreclaimingβ a page frame from the list of pages awaiting reallocation. lowkey efficient πru_majfltβ the number of page faults serviced that did require I/O activity. the dramatic ones πru_nswapβ the number of times a process was βswappedβ out of main memory.ru_inblockβ the number of times the file system had to perform input.ru_oublockβ the number of times the file system had to perform output.ru_msgsndβ the number of IPC messages sent.ru_msgrcvβ the number of IPC messages received.ru_nsignalsβ the number of signals delivered.ru_nvcswβ the number of times a context switch resulted due to a process voluntarily giving up the processor before its time slice was completed. usually it does this to await availability of a resource. so polite of it π«Άru_nivcswβ the number of times a context switch resulted due to a higher priority process becoming runnable, or because the current process exceeded its time slice. not so polite, but we respect the hustle π
π NOTES π
Heads up bestie: the numbers ru_inblock and ru_oublock account only for real I/O. data supplied by the caching mechanism is charged only to the first process to read or write the data. so if it looks suspiciously small, that's why π
πΈ RETURN VALUES πΈ
The getrusage() function returns the value 0 if successful β icon behavior. otherwise the value -1 is returned and the global variable errno is set to indicate the error. sad girl hours π
π ERRORS π
The getrusage() system call will fail if:
[EINVAL]β Thewhoargument is not a valid value. you gave it a vibe it doesn't recognize π«[EFAULT]β The address specified by therusageargument is not in a valid part of the process address space. it's pointing into the void, bestie π
β SEE ALSO β
gettimeofday(2), wait(2), clocks(7)
π HISTORY π
The getrusage() system call appeared in 4.2BSD. The RUSAGE_THREAD facility first appeared in FreeBSD 8.1. ancient lore, but make it fashion π
π BUGS π
There is no way to obtain information about a child process that has not yet terminated. so if it's still alive and kicking, you simply cannot peek. patience, bestie π¦
and that's the whole page, periodt π
this was the Debian edition, dated May 1, 2010 β thanks for reading my ted talk, ily, go check your rusage π«Άπβ¨
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 1985, 1991, 1993 The Regents of the University of California. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms