O'Reilly logo

Hands-On System Programming with Linux by Kaiwan N Billimoria

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

API interfaces

Querying and/or setting resource limits programmatically can be achieved with the following APIsthe system calls:

  • getrlimit
  • setrlimit
  • prlimit

Of these, we will only focus on prlimit(2); [get|set]rlimit(2) is an older interface, has quite a few issues (bugs), and is generally considered outdated.

For prlimit(2) to work properly, one must be running on Linux kernel version 2.6.36 or later.
How does one determine the Linux kernel version one is running on? Simple: use the uname utility to query the kernel version: $ uname -r 4.14.11-300.fc27.x86_64 $

Let's get back to the prlimit(2) system call API:

#include <sys/time.h>#include <sys/resource.h>int prlimit(pid_t pid, int resource,  const struct rlimit *new_limit, struct rlimit ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required