`getrlimit()` 和 `setr​​limit()` 是否通过读取和写入 `/etc/security/limits.conf` 来工作?

Do `getrlimit()` and `setrlimit()` work by reading from and writing to `/etc/security/limits.conf`?

在Linux(例如Ubuntu 18.04或其他)中,getrlimit()setrlimit()通过读取和写入/etc/security/limits.conf来工作吗?

我正在尝试了解 getrlimit()setrlimit() 以及 /etc/security/limits.conf 之间的关系。谢谢。

事实上,情况正好相反:/etc/security/limits.conf 控制对 getrlimitsetrlimit 的调用。

getrlimitsetrlimit 读取和写入与调用进程关联的内核状态。他们根本不访问任何文件。与大多数与特定进程关联的内核状态一样,资源限制是 继承的 (复制到)fork 子级。

/etc/security/limits.conf 永远不会自动修改(除非可能通过系统升级);它供系统管理员手动编辑。

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,为用户初始建立资源限制shell。这些资源限制然后继承到由 shell 启动的所有进程,依此类推。