Reputation: 99408
In Linux (e.g. Ubuntu 18.04 or other), do getrlimit()
and setrlimit()
work by reading from and writing to /etc/security/limits.conf
?
I am trying to understand the relations between getrlimit()
and setrlimit()
and /etc/security/limits.conf
. Thanks.
Upvotes: 1
Views: 788
Reputation: 140455
In fact, it's the other way around: /etc/security/limits.conf
controls calls made to getrlimit
and setrlimit
.
getrlimit
and setrlimit
read and write kernel state associated with the calling process. They do not access any file at all. Like most kernel state associated with a particular process, the resource limits are inherited (copied into) fork
-ed children.
/etc/security/limits.conf
is never modified automatically (except possibly by a system upgrade); it's intended for the sysadmin to edit, by hand.
The login
program (technically, the pam_limits module that it may load, and does load in Ubuntu 18's default configuration) reads /etc/security/limits.conf
, and uses the information in that file to make a series of calls to setrlimit
, establishing resource limits for the user's initial shell. Those resource limits then inherit to all processes started by the shell, and so on transitively.
Upvotes: 4