luaposix 36.3 Reference

# Module `posix.sys.resource`

Control Maximum System Resource Consumption.

## Functions

getrlimit (resource) | Get resource limits for this process.
setrlimit (resource[, softlimit[, hardlimit]]) | Set a resource limit for subsequent child processes.

## Tables

PosixRlimit | Resource limit record.

## Constants

posix.sys.resource | Rlimit constants.

## Functions

getrlimit (resource)
  Get resource limits for this process.

  ### Parameters:

  - resource int one of `RLIMIT_CORE`, `RLIMIT_CPU`, `RLIMIT_DATA`, `RLIMIT_FSIZE`, `RLIMIT_NOFILE`, `RLIMIT_STACK` or `RLIMIT_AS`

  ### Returns:

  1. int softlimit
  2. int hardlimit, if successful

  ### Or

  1. nil
  2. string error message
  3. int errnum

  ### See also:

  - getrlimit(2)
  - setrlimit

  ### Usage:

      local sysres = require "posix.sys.resource"
      sysres.getrlimit(sysres.RLIMIT_NOFILE)

setrlimit (resource[, softlimit[, hardlimit]])
  Set a resource limit for subsequent child processes.

  ### Parameters:

  - resource int one of `RLIMIT_CORE`, `RLIMIT_CPU`, `RLIMIT_DATA`, `RLIMIT_FSIZE`, `RLIMIT_NOFILE`, `RLIMIT_STACK` or `RLIMIT_AS`
  - softlimit process may receive a signal when reached (optional)
  - hardlimit process may be terminated when reached (optional)

  ### Returns:

  int `0`, if successful

  ### Or

  1. nil
  2. string error message
  3. int errnum

  ### See also:

  - setrlimit(2)
  - getrlimit
  - limit.lua

  ### Usage:

      local sysres = require "posix.sys.resource"
      local lim = sysres.getlimit(sysres.RLIMIT_NOFILE)
      lim.rlim_cur = lim.rlim_cur / 2
      sysres.setrlimit(sysres.RLIMIT_NOFILE, lim)

## Tables

PosixRlimit
  Resource limit record.

  ### Fields:

  - rlim_cur int current soft limit
  - rlim_max int hard limit

## Constants

posix.sys.resource
  Rlimit constants.

  ### Fields:

  - RLIM_INFINITY int unlimited resource usage
  - RLIM_SAVED_CUR int saved current resource soft limit
  - RLIM_SAVED_MAX int saved resource hard limit
  - RLIMIT_CORE int maximum bytes allowed for a core file
  - RLIMIT_CPU int maximum cputime secconds allowed per process
  - RLIMIT_DATA int maximum data segment bytes per process
  - RLIMIT_FSIZE int maximum bytes in any file
  - RLIMIT_NOFILE int maximum number of open files per process
  - RLIMIT_STACK int maximum stack segment bytes per process
  - RLIMIT_AS int maximum bytes total address space per process

  ### Usage:

      -- Print resource constants supported on this host.
      for name, value in pairs (require "posix.sys.resource") do
        if type (value) == "number" then
          print (name, value)
         end
      end

generated by LDoc 1.5.0 Last updated 2025-02-16 13:16:41