Each process consumes system resources such as memory and CPU time. This chapter looks at resource-related system calls. We begin with the getrusage() system call, which allows a process to monitor the resources that it has used or that its children have used. We then look at the setrlimit() and getrlimit() system calls, which can be used to change and retrieve limits on the calling process’s consumption of various resources.

36.1 Process Resource Usage

The getrusage() system call retrieves statistics about various system resources used by the calling process or by all of its children.

#include <sys/resource.h>int getrusage(int who, struct rusage *res_usage);

Returns 0 on success, or –1 on error

The who argument specifies ...

Get The Linux Programming Interface now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.