mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-22 09:45:25 +08:00
ulimit: add new limits from Linux
Short options are taken from prlimit(1) where appropriate. Closes #8786.
This commit is contained in:
parent
ee69a2467e
commit
2c2b87af07
|
@ -34,6 +34,7 @@ Interactive improvements
|
|||
- The default command-not-found handler now reports a special error if there is a non-executable file (:issue:`8804`)
|
||||
- ``less`` and other interactive commands would occasionally be stopped when run in a pipeline with fish functions; this has been fixed (:issue:`8699`).
|
||||
- Case-changing autosuggestions generated mid-token now correctly append only the suffix, instead of duplicating the token (:issue:`8820`).
|
||||
- ``ulimit`` learned a number of new options for the resource limits available on Linux (:issue:`8786`).
|
||||
|
||||
New or improved bindings
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
|
@ -24,9 +24,15 @@ Use one of the following switches to specify which resource limit to set or repo
|
|||
**-d** or **--data-size**
|
||||
The maximum size of a process' data segment.
|
||||
|
||||
**-e** or **--nice**
|
||||
Controls the maximum nice value; on Linux, this value is subtracted from 20 to give the effective value.
|
||||
|
||||
**-f** or **--file-size**
|
||||
The maximum size of files created by a process.
|
||||
|
||||
**-i** or **--pending-signals**
|
||||
The maximum number of signals that may be queued.
|
||||
|
||||
**-l** or **--lock-size**
|
||||
The maximum size that may be locked into memory.
|
||||
|
||||
|
@ -36,6 +42,12 @@ Use one of the following switches to specify which resource limit to set or repo
|
|||
**-n** or **--file-descriptor-count**
|
||||
The maximum number of open file descriptors.
|
||||
|
||||
**-q** or **--queue-size**
|
||||
The maximum size of data in POSIX message queues.
|
||||
|
||||
**-r** or **--realtime-priority**
|
||||
The maximum realtime scheduling priority.
|
||||
|
||||
**-s** or **--stack-size**
|
||||
The maximum stack size.
|
||||
|
||||
|
@ -48,6 +60,9 @@ Use one of the following switches to specify which resource limit to set or repo
|
|||
**-v** or **--virtual-memory-size**
|
||||
The maximum amount of virtual memory available to the shell.
|
||||
|
||||
**-y** or **--realtime-maxtime**
|
||||
The maximum contiguous realtime CPU time in microseconds.
|
||||
|
||||
Note that not all these limits are available in all operating systems.
|
||||
|
||||
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.
|
||||
|
|
|
@ -5,14 +5,19 @@ complete -c ulimit -s H -l hard -d "Set or get hard limit"
|
|||
complete -c ulimit -s a -l all -d "Get all current limits"
|
||||
complete -c ulimit -s c -l core-size -d "Maximum size of core files created"
|
||||
complete -c ulimit -s d -l data-size -d "Maximum size of a process's data segment"
|
||||
complete -c ulimit -s e -l nice -d "Control of maximum nice priority"
|
||||
complete -c ulimit -s f -l file-size -d "Maximum size of files created by the shell"
|
||||
complete -c ulimit -s i -l pending-signals -d "Maximum number of pending signals"
|
||||
complete -c ulimit -s l -l lock-size -d "Maximum size that may be locked into memory"
|
||||
complete -c ulimit -s m -l resident-set-size -d "Maximum resident set size"
|
||||
complete -c ulimit -s n -l file-descriptor-count -d "Maximum number of open file descriptors"
|
||||
complete -c ulimit -s q -l queue-size -d "Maximum bytes in POSIX message queues"
|
||||
complete -c ulimit -s r -l realtime-priority -d "Maximum realtime scheduling priority"
|
||||
complete -c ulimit -s s -l stack-size -d "Maximum stack size"
|
||||
complete -c ulimit -s t -l cpu-time -d "Maximum amount of cpu time in seconds"
|
||||
complete -c ulimit -s u -l process-count -d "Maximum number of processes available to a single user"
|
||||
complete -c ulimit -s v -l virtual-memory-size -d "Maximum amount of virtual memory available to the shell"
|
||||
complete -c ulimit -s y -l realtime-maxtime -d "Maximum contiguous realtime CPU time"
|
||||
|
||||
complete -c ulimit -s h -l help -d "Display help and exit"
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#include "config.h" // IWYU pragma: keep
|
||||
|
||||
#include "ulimit.h"
|
||||
|
||||
|
||||
#include <sys/resource.h>
|
||||
|
||||
#include <cerrno>
|
||||
|
@ -28,7 +28,13 @@ struct resource_t {
|
|||
static const struct resource_t resource_arr[] = {
|
||||
{RLIMIT_CORE, L"Maximum size of core files created", L'c', 1024},
|
||||
{RLIMIT_DATA, L"Maximum size of a process’s data segment", L'd', 1024},
|
||||
#ifdef RLIMIT_NICE
|
||||
{RLIMIT_NICE, L"Control of maximum nice priority", L'e', 1},
|
||||
#endif
|
||||
{RLIMIT_FSIZE, L"Maximum size of files created by the shell", L'f', 1024},
|
||||
#ifdef RLIMIT_SIGPENDING
|
||||
{RLIMIT_SIGPENDING, L"Maximum number of pending signals", L'i', 1},
|
||||
#endif
|
||||
#ifdef RLIMIT_MEMLOCK
|
||||
{RLIMIT_MEMLOCK, L"Maximum size that may be locked into memory", L'l', 1024},
|
||||
#endif
|
||||
|
@ -36,6 +42,12 @@ static const struct resource_t resource_arr[] = {
|
|||
{RLIMIT_RSS, L"Maximum resident set size", L'm', 1024},
|
||||
#endif
|
||||
{RLIMIT_NOFILE, L"Maximum number of open file descriptors", L'n', 1},
|
||||
#ifdef RLIMIT_MSGQUEUE
|
||||
{RLIMIT_MSGQUEUE, L"Maximum bytes in POSIX message queues", L'q', 1024},
|
||||
#endif
|
||||
#ifdef RLIMIT_RTPRIO
|
||||
{RLIMIT_RTPRIO, L"Maximum realtime scheduling priority", L'r', 1},
|
||||
#endif
|
||||
{RLIMIT_STACK, L"Maximum stack size", L's', 1024},
|
||||
{RLIMIT_CPU, L"Maximum amount of CPU time in seconds", L't', 1},
|
||||
#ifdef RLIMIT_NPROC
|
||||
|
@ -43,6 +55,9 @@ static const struct resource_t resource_arr[] = {
|
|||
#endif
|
||||
#ifdef RLIMIT_AS
|
||||
{RLIMIT_AS, L"Maximum amount of virtual memory available to each process", L'v', 1024},
|
||||
#endif
|
||||
#ifdef RLIMIT_RTTIME
|
||||
{RLIMIT_RTTIME, L"Maximum contiguous realtime CPU time", L'y', 1},
|
||||
#endif
|
||||
{0, nullptr, 0, 0}};
|
||||
|
||||
|
@ -158,21 +173,26 @@ maybe_t<int> builtin_ulimit(parser_t &parser, io_streams_t &streams, const wchar
|
|||
bool soft = false;
|
||||
int what = RLIMIT_FSIZE;
|
||||
|
||||
static const wchar_t *const short_options = L":HSacdflmnstuvh";
|
||||
static const wchar_t *const short_options = L":HSacdefilmnqrstuvyh";
|
||||
static const struct woption long_options[] = {
|
||||
{L"all", no_argument, nullptr, 'a'},
|
||||
{L"hard", no_argument, nullptr, 'H'},
|
||||
{L"soft", no_argument, nullptr, 'S'},
|
||||
{L"core-size", no_argument, nullptr, 'c'},
|
||||
{L"data-size", no_argument, nullptr, 'd'},
|
||||
{L"nice", no_argument, nullptr, 'e'},
|
||||
{L"file-size", no_argument, nullptr, 'f'},
|
||||
{L"pending-signals", no_argument, nullptr, 'i'},
|
||||
{L"lock-size", no_argument, nullptr, 'l'},
|
||||
{L"resident-set-size", no_argument, nullptr, 'm'},
|
||||
{L"file-descriptor-count", no_argument, nullptr, 'n'},
|
||||
{L"queue-size", no_argument, nullptr, 'q'},
|
||||
{L"realtime-priority", no_argument, nullptr, 'r'},
|
||||
{L"stack-size", no_argument, nullptr, 's'},
|
||||
{L"cpu-time", no_argument, nullptr, 't'},
|
||||
{L"process-count", no_argument, nullptr, 'u'},
|
||||
{L"virtual-memory-size", no_argument, nullptr, 'v'},
|
||||
{L"realtime-maxtime", no_argument, nullptr, 'y'},
|
||||
{L"help", no_argument, nullptr, 'h'},
|
||||
{nullptr, 0, nullptr, 0}};
|
||||
|
||||
|
@ -200,10 +220,22 @@ maybe_t<int> builtin_ulimit(parser_t &parser, io_streams_t &streams, const wchar
|
|||
what = RLIMIT_DATA;
|
||||
break;
|
||||
}
|
||||
#ifdef RLIMIT_NICE
|
||||
case 'e': {
|
||||
what = RLIMIT_NICE;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
case 'f': {
|
||||
what = RLIMIT_FSIZE;
|
||||
break;
|
||||
}
|
||||
#ifdef RLIMIT_SIGPENDING
|
||||
case 'i': {
|
||||
what = RLIMIT_SIGPENDING;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#ifdef RLIMIT_MEMLOCK
|
||||
case 'l': {
|
||||
what = RLIMIT_MEMLOCK;
|
||||
|
@ -220,6 +252,18 @@ maybe_t<int> builtin_ulimit(parser_t &parser, io_streams_t &streams, const wchar
|
|||
what = RLIMIT_NOFILE;
|
||||
break;
|
||||
}
|
||||
#ifdef RLIMIT_MSGQUEUE
|
||||
case 'q': {
|
||||
what = RLIMIT_MSGQUEUE;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#ifdef RLIMIT_RTPRIO
|
||||
case 'r': {
|
||||
what = RLIMIT_RTPRIO;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
case 's': {
|
||||
what = RLIMIT_STACK;
|
||||
break;
|
||||
|
@ -239,6 +283,12 @@ maybe_t<int> builtin_ulimit(parser_t &parser, io_streams_t &streams, const wchar
|
|||
what = RLIMIT_AS;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#ifdef RLIMIT_RTTIME
|
||||
case 'y': {
|
||||
what = RLIMIT_RTTIME;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
case 'h': {
|
||||
builtin_print_help(parser, streams, cmd);
|
||||
|
|
Loading…
Reference in New Issue
Block a user