2019-03-31 17:05:09 +08:00
.. _cmd-ulimit:
2018-12-17 09:39:33 +08:00
ulimit - set or get resource usage limits
2019-01-03 12:10:47 +08:00
=========================================
2018-12-17 09:39:33 +08:00
2018-12-18 09:58:24 +08:00
Synopsis
--------
2018-12-17 05:08:41 +08:00
docs synopsis: add HTML highlighing and automate manpage markup
Recent synopsis changes move from literal code blocks to
[RST line blocks]. This does not translate well to HTML: it's not
rendered in monospace, so aligment is lost. Additionally, we don't
get syntax highlighting in HTML, which adds differences to our code
samples which are highlighted.
We hard-wrap synopsis lines (like code blocks). To align continuation
lines in manpages we need [backslashes in weird places]. Combined with
the **, *, and `` markup, it's a bit hard to get the alignment right.
Fix these by moving synopsis sources back to code blocks and compute
HTML syntax highlighting and manpage markup with a custom Sphinx
extension.
The new Pygments lexer can tokenize a synopsis and assign the various
highlighting roles, which closely matches fish's syntax highlighing:
- command/keyword (dark blue)
- parameter (light blue)
- operator like and/or/not/&&/|| (cyan)
- grammar metacharacter (black)
For manpage output, we don't project the fish syntax highlighting
but follow the markup convention in GNU's man(1):
bold text type exactly as shown.
italic text replace with appropriate argument.
To make it easy to separate these two automatically, formalize that
(italic) placeholders must be uppercase; while all lowercase text is
interpreted literally (so rendered bold).
This makes manpages more consistent, see string-join(1) and and(1).
Implementation notes:
Since we want manpage formatting but Sphinx's Pygments highlighing
plugin does not support manpage output, add our custom "synopsis"
directive. This directive parses differently when manpage output is
specified. This means that the HTML and manpage build processes must
not share a cache, because the parsed doctrees are cached. Work around
this by using separate cache locations for build targets "sphinx-docs"
(which creates HTML) and "sphinx-manpages". A better solution would
be to only override Sphinx's ManualPageBuilder but that would take a
bit more code (ideally we could override ManualPageWriter but Sphinx
4.3.2 doesn't really support that).
---
Alternative solution: stick with line blocks but use roles like
:command: or :option: (or custom ones). While this would make it
possible to produce HTML that is consistent with code blocks (by adding
a bit of CSS), the source would look uglier and is harder to maintain.
(Let's say we want to add custom formatting to the [|] metacharacters
in HTML. This is much easier with the proposed patch.)
---
[RST line blocks]: https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#line-blocks
[backslashes in weird places]: https://github.com/fish-shell/fish-shell/pull/8626#discussion_r782837750
2022-01-09 22:09:46 +08:00
.. synopsis ::
2022-01-17 12:29:49 +08:00
ulimit [OPTIONS] [LIMIT]
2018-12-18 09:58:24 +08:00
2018-12-17 05:08:41 +08:00
2018-12-19 10:44:30 +08:00
Description
2019-01-03 12:10:47 +08:00
-----------
2018-12-17 05:08:41 +08:00
2020-03-21 22:31:25 +08:00
`` ulimit `` sets or outputs the resource usage limits of the shell and any processes spawned by it. If a new limit value is omitted, the current value of the limit of the resource is printed; otherwise, the specified limit is set to the new value.
2018-12-17 05:08:41 +08:00
Use one of the following switches to specify which resource limit to set or report:
2022-03-23 21:49:09 +08:00
**-b** or **--socket-buffers**
The maximum size of socket buffers.
2022-03-11 23:56:20 +08:00
**-c** or **--core-size**
The maximum size of core files created. By setting this limit to zero, core dumps can be disabled.
2018-12-17 05:08:41 +08:00
2022-03-11 23:56:20 +08:00
**-d** or **--data-size**
The maximum size of a process' data segment.
2018-12-17 05:08:41 +08:00
2022-03-21 23:36:41 +08:00
**-e** or **--nice**
Controls the maximum nice value; on Linux, this value is subtracted from 20 to give the effective value.
2022-03-11 23:56:20 +08:00
**-f** or **--file-size**
2022-03-21 23:33:47 +08:00
The maximum size of files created by a process.
2018-12-17 05:08:41 +08:00
2022-03-21 23:36:41 +08:00
**-i** or **--pending-signals**
The maximum number of signals that may be queued.
2022-03-11 23:56:20 +08:00
**-l** or **--lock-size**
The maximum size that may be locked into memory.
2018-12-17 05:08:41 +08:00
2022-03-11 23:56:20 +08:00
**-m** or **--resident-set-size**
The maximum resident set size.
2018-12-17 05:08:41 +08:00
2022-03-11 23:56:20 +08:00
**-n** or **--file-descriptor-count**
2022-03-21 23:33:47 +08:00
The maximum number of open file descriptors.
2018-12-17 05:08:41 +08:00
2022-03-21 23:36:41 +08:00
**-q** or **--queue-size**
The maximum size of data in POSIX message queues.
**-r** or **--realtime-priority**
The maximum realtime scheduling priority.
2022-03-11 23:56:20 +08:00
**-s** or **--stack-size**
The maximum stack size.
2018-12-17 05:08:41 +08:00
2022-03-11 23:56:20 +08:00
**-t** or **--cpu-time**
The maximum amount of CPU time in seconds.
2018-12-17 05:08:41 +08:00
2022-03-11 23:56:20 +08:00
**-u** or **--process-count**
2022-03-21 23:33:47 +08:00
The maximum number of processes available to the current user.
2018-12-17 05:08:41 +08:00
2022-03-23 21:49:09 +08:00
**-w** or **--swap-size**
The maximum swap space available to the current user.
2022-03-11 23:56:20 +08:00
**-v** or **--virtual-memory-size**
The maximum amount of virtual memory available to the shell.
2018-12-17 05:08:41 +08:00
2022-03-21 23:36:41 +08:00
**-y** or **--realtime-maxtime**
The maximum contiguous realtime CPU time in microseconds.
2022-03-23 21:49:09 +08:00
**-K** or **--kernel-queues**
The maximum number of kqueues (kernel queues) for the current user.
**-P** or **--ptys**
The maximum number of pseudo-terminals for the current user.
**-T** or **--threads**
The maximum number of simultaneous threads for the current user.
Note that not all these limits are available in all operating systems; consult the documentation for `` setrlimit `` in your operating system.
2018-12-17 05:08:41 +08:00
2018-12-20 04:02:45 +08:00
The value of limit can be a number in the unit specified for the resource or one of the special values `` hard `` , `` soft `` , or `` unlimited `` , which stand for the current hard limit, the current soft limit, and no limit, respectively.
2018-12-17 05:08:41 +08:00
2022-03-11 23:56:20 +08:00
If limit is given, it is the new value of the specified resource. If no option is given, then **-f** is assumed. Values are in kilobytes, except for **-t** , which is in seconds and **-n** and **-u** , which are unscaled values. The exit status is 0 unless an invalid option or argument is supplied, or an error occurs while setting a new limit.
2018-12-17 05:08:41 +08:00
2022-03-21 23:33:47 +08:00
`` ulimit `` also accepts the following options that determine what type of limit to set:
2018-12-17 05:08:41 +08:00
2022-03-11 23:56:20 +08:00
**-H** or **--hard**
Sets hard resource limit.
2018-12-17 05:08:41 +08:00
2022-03-11 23:56:20 +08:00
**-S** or **--soft**
Sets soft resource limit.
2018-12-17 05:08:41 +08:00
2022-03-11 23:56:20 +08:00
A hard limit can only be decreased. Once it is set it cannot be increased; a soft limit may be increased up to the value of the hard limit. If neither **-H** nor **-S** is specified, both the soft and hard limits are updated when assigning a new limit value, and the soft limit is used when reporting the current value.
2018-12-17 05:08:41 +08:00
2018-12-20 04:02:45 +08:00
The following additional options are also understood by `` ulimit `` :
2018-12-17 05:08:41 +08:00
2022-03-11 23:56:20 +08:00
**-a** or **--all**
Prints all current limits.
2018-12-17 05:08:41 +08:00
2022-03-12 00:18:41 +08:00
**-h** or **--help**
Displays help about using this command.
2018-12-20 04:02:45 +08:00
The `` fish `` implementation of `` ulimit `` should behave identically to the implementation in bash, except for these differences:
2018-12-17 05:08:41 +08:00
2022-03-12 00:18:41 +08:00
- Fish `` ulimit `` supports GNU-style long options for all switches.
2018-12-17 05:08:41 +08:00
2022-09-17 19:38:33 +08:00
- Fish `` ulimit `` does not support the **-p** option for getting the pipe size. The bash implementation consists of a compile-time check that empirically guesses this number by writing to a pipe and waiting for SIGPIPE. Fish does not do this because this method of determining pipe size is unreliable. Depending on bash version, there may also be further additional limits to set in bash that do not exist in fish.
2018-12-17 05:08:41 +08:00
2022-03-12 00:18:41 +08:00
- Fish `` ulimit `` does not support getting or setting multiple limits in one command, except reporting all values using the **-a** switch.
2018-12-17 05:08:41 +08:00
2018-12-19 10:44:30 +08:00
Example
2019-01-03 12:10:47 +08:00
-------
2018-12-17 05:08:41 +08:00
2018-12-20 04:02:45 +08:00
`` ulimit -Hs 64 `` sets the hard stack size limit to 64 kB.
2018-12-17 05:08:41 +08:00