1GETRUSAGE(2)               Linux Programmer's Manual              GETRUSAGE(2)
2
3
4

NAME

6       getrusage - get resource usage
7

SYNOPSIS

9       #include <sys/time.h>
10       #include <sys/resource.h>
11
12       int getrusage(int who, struct rusage *usage);
13

DESCRIPTION

15       getrusage()  returns  current  resource  usages,  for  a  who of either
16       RUSAGE_SELF or RUSAGE_CHILDREN.  The former asks for resources used  by
17       the  current  process,  the  latter  for resources used by those of its
18       children that have terminated and have been waited for.
19
20            struct rusage {
21                struct timeval ru_utime; /* user time used */
22                struct timeval ru_stime; /* system time used */
23                long   ru_maxrss;        /* maximum resident set size */
24                long   ru_ixrss;         /* integral shared memory size */
25                long   ru_idrss;         /* integral unshared data size */
26                long   ru_isrss;         /* integral unshared stack size */
27                long   ru_minflt;        /* page reclaims */
28                long   ru_majflt;        /* page faults */
29                long   ru_nswap;         /* swaps */
30                long   ru_inblock;       /* block input operations */
31                long   ru_oublock;       /* block output operations */
32                long   ru_msgsnd;        /* messages sent */
33                long   ru_msgrcv;        /* messages received */
34                long   ru_nsignals;      /* signals received */
35                long   ru_nvcsw;         /* voluntary context switches */
36                long   ru_nivcsw;        /* involuntary context switches */
37            };
38

RETURN VALUE

40       On success, zero is returned.  On error, -1 is returned, and  errno  is
41       set appropriately.
42

ERRORS

44       EFAULT usage points outside the accessible address space.
45
46       EINVAL who is invalid.
47

CONFORMING TO

49       SVr4,  4.3BSD.   POSIX.1-2001 specifies getrusage(), but only specifies
50       the fields ru_utime and ru_stime.
51

NOTES

53       Including <sys/time.h> is not required these days, but increases porta‐
54       bility.  (Indeed, struct timeval is defined in <sys/time.h>.)
55
56       In Linux kernel versions before 2.6.9, if the disposition of SIGCHLD is
57       set to SIG_IGN then the resource usages of child processes are automat‐
58       ically  included  in  the  value  returned by RUSAGE_CHILDREN, although
59       POSIX.1-2001 explicitly prohibits this.  This non-conformance is recti‐
60       fied in Linux 2.6.9 and later.
61
62       The  above struct was taken from 4.3BSD Reno.  Not all fields are mean‐
63       ingful under Linux.  In linux 2.4 only the fields  ru_utime,  ru_stime,
64       ru_minflt, and ru_majflt are maintained.  Since Linux 2.6, ru_nvcsw and
65       ru_nivcsw are also maintained.
66

SEE ALSO

68       getrlimit(2), times(2), wait(2), wait4(2)
69
70
71
72Linux 2.6.9                       2004-11-16                      GETRUSAGE(2)
Impressum