Linux nproc 和 ulimit 的区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13875081/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Difference between nproc and ulimit?
提问by udi
Ulimit and nproc are both used for limiting the system processes and resources for a particular user or application (correct me if I am wrong) in *nix system. What is the major difference between the two?
Ulimit 和 nproc 都用于限制 *nix 系统中特定用户或应用程序的系统进程和资源(如果我错了,请纠正我)。两者之间的主要区别是什么?
回答by Lev Levitsky
nproc
from coreutils
prints the number of processors. From man nproc
:
nproc
fromcoreutils
打印处理器的数量。来自man nproc
:
NPROC(1) User Commands NPROC(1)
NAME
nproc - print the number of processing units available
SYNOPSIS
nproc [OPTION]...
DESCRIPTION
Print the number of processing units available to the current process,
which may be less than the number of online processors
However, the nproc
setting in /etc/security/limits.conf
indeed limits the number of processes:
但是,nproc
设置/etc/security/limits.conf
确实限制了进程的数量:
From man limits.conf
:
来自man limits.conf
:
nproc
maximum number of processes
回答by P.P
both are used for limiting the system processes and resources
If you are referring to the nproc parameter in limits.confthen yes it's for limiting the number of processes.
如果您指的是limits.conf 中的nproc 参数,那么是的,它用于限制进程数。
The shell utility ulimitis used for getting/setting resources' limits, too. For example, getting the stack size for each process:
shell 实用程序ulimit也用于获取/设置资源的限制。例如,获取每个进程的堆栈大小:
$ulimit -s
Changing the stack size to 1MB:
将堆栈大小更改为 1MB:
$ulimit -s 1024
Changing the stack size to unlimited
:
将堆栈大小更改为unlimited
:
$ulimit -s unlimited
There's no difference between setting/changing resources via /etc/security/limits.conf`` and
ulimit`.
通过/etc/security/limits.conf`` and
ulimit`设置/更改资源没有区别。
However, the shell utility ulimit
changes are only applicable to the current shell. But /etc/security/limits.conf changes will be applicable system-wide for all the specified users. Besides /etc/security/limits.conf typically can be changed only by a privileged users.
但是,shell 实用程序ulimit
更改仅适用于当前 shell。但是 /etc/security/limits.conf 更改将适用于所有指定用户的系统范围。此外/etc/security/limits.conf 通常只能由特权用户更改。
But ulimit
doesn't require privileges.
但ulimit
不需要特权。
So you can think of ulimit
as for temporary changes to resource limits just for you, which you can change yourself; whereas /etc/security/limits.conf
is for system-wide setting (for one or more users) which you can't usually change (typically your system administrators sets resource limits, if any).
所以你可以把ulimit
资源限制想成只为你自己临时改变,你可以自己改变;而/etc/security/limits.conf
用于系统范围的设置(对于一个或多个用户),您通常无法更改(通常您的系统管理员会设置资源限制,如果有的话)。
Whereas nproc(1)
utliity is totally different which just lists the available number of processors.
而nproc(1)
utliity 则完全不同,它只列出了可用的处理器数量。