pub fn setrlimit(
resource: Resource,
soft_limit: Option<rlim_t>,
hard_limit: Option<rlim_t>,
) -> Result<()>
Expand description
Set the current processes resource limits
§Parameters
resource
: TheResource
that we want to set the limits of.soft_limit
: The value that the kernel enforces for the corresponding resource. Note:None
input will be replaced by constantRLIM_INFINITY
.hard_limit
: The ceiling for the soft limit. Must be lower or equal to the current hard limit for non-root users. Note:None
input will be replaced by constantRLIM_INFINITY
.
Note: for some os (linux_gnu), setting hard_limit to
RLIM_INFINITY
can resultsEPERM
Error. So you will need to set the number explicitly.
§Examples
let soft_limit = Some(512);
let hard_limit = Some(1024);
setrlimit(Resource::RLIMIT_NOFILE, soft_limit, hard_limit).unwrap();
§References
Note: setrlimit
provides a safe wrapper to libc’s setrlimit
.