rlimit.d.elv 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #elvdoc:var rlimits
  2. #
  3. # A map describing resource limits of the current process.
  4. #
  5. # Each key is a string corresponds to a resource, and each value is a map with
  6. # keys `&cur` and `&max`, describing the soft and hard limits of that resource.
  7. # A missing `&cur` key means that there is no soft limit; a missing `&max` key
  8. # means that there is no hard limit.
  9. #
  10. # The following resources are supported, some only present on certain OSes:
  11. #
  12. # | Key | Resource | Unit | OS |
  13. # | ------------ | ------------------ | ------- | ------------------ |
  14. # | `core` | Core file | bytes | all |
  15. # | `cpu` | CPU time | seconds | all |
  16. # | `data` | Data segment | bytes | all |
  17. # | `fsize` | File size | bytes | all |
  18. # | `memlock` | Locked memory | bytes | all |
  19. # | `nofile` | File descriptors | number | all |
  20. # | `nproc` | Processes | number | all |
  21. # | `rss` | Resident set size | bytes | all |
  22. # | `stack` | Stack segment | bytes | all |
  23. # | `as` | Address space | bytes | Linux, Free/NetBSD |
  24. # | `nthr` | Threads | number | NetBSD |
  25. # | `sbsize` | Socket buffers | bytes | NetBSD |
  26. # | `locks` | File locks | number | Linux |
  27. # | `msgqueue` | Message queues | bytes | Linux |
  28. # | `nice` | 20 - nice value | | Linux |
  29. # | `rtprio` | Real-time priority | | Linux |
  30. # | `rttime` | Real-time CPU time | seconds | Linux |
  31. # | `sigpending` | Signals queued | number | Linux |
  32. #
  33. # For the exact semantics of each resource, see the man page of `getrlimit`:
  34. # [Linux](https://man7.org/linux/man-pages/man2/setrlimit.2.html),
  35. # [macOS](https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/getrlimit.2.html),
  36. # [FreeBSD](https://www.freebsd.org/cgi/man.cgi?query=getrlimit),
  37. # [NetBSD](https://man.netbsd.org/getrlimit.2),
  38. # [OpenBSD](https://man.openbsd.org/getrlimit.2). A key `foo` in the Elvish API
  39. # corresponds to `RLIMIT_FOO` in the C API.
  40. #
  41. # Examples:
  42. #
  43. # ```elvish-transcript
  44. # ~> put $unix:rlimits
  45. # ▶ [&nofile=[&cur=(num 256)] &fsize=[&] &nproc=[&max=(num 2666) &cur=(num 2666)] &memlock=[&] &cpu=[&] &core=[&cur=(num 0)] &stack=[&max=(num 67092480) &cur=(num 8372224)] &rss=[&] &data=[&]]
  46. # ~> # mimic Bash's "ulimit -a"
  47. # ~> keys $unix:rlimits | order | each {|key|
  48. # var m = $unix:rlimits[$key]
  49. # fn get {|k| if (has-key $m $k) { put $m[$k] } else { put unlimited } }
  50. # printf "%-7v %-9v %-9v\n" $key (get cur) (get max)
  51. # }
  52. # core 0 unlimited
  53. # cpu unlimited unlimited
  54. # data unlimited unlimited
  55. # fsize unlimited unlimited
  56. # memlock unlimited unlimited
  57. # nofile 256 unlimited
  58. # nproc 2666 2666
  59. # rss unlimited unlimited
  60. # stack 8372224 67092480
  61. # ~> # Decrease the soft limit on file descriptors
  62. # ~> set unix:rlimits[nofile][cur] = 100
  63. # ~> put $unix:rlimits[nofile]
  64. # ▶ [&cur=(num 100)]
  65. # ~> # Remove the soft limit on file descriptors
  66. # ~> del unix:rlimits[nofile][cur]
  67. # ~> put $unix:rlimits[nofile]
  68. # ▶ [&]
  69. # ```