Reputation: 508
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?
Upvotes: 14
Views: 58891
Reputation: 65791
There are two different instances of nproc
.
nproc
from coreutils
prints the number of processors. From 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:
From man limits.conf
:
nproc
maximum number of processes
Upvotes: 20
Reputation: 121387
both are used for limiting the system processes and resources
If you are referring to the nproc parameter in limits.conf then yes it's for limiting the number of processes.
The shell utility ulimit is used for getting/setting resources' limits, too. For example, getting the stack size for each process:
$ulimit -s
Changing the stack size to 1MB:
$ulimit -s 1024
Changing the stack size to unlimited
:
$ulimit -s unlimited
There's no difference between setting/changing resources via /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.
But ulimit
doesn't require privileges.
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).
Whereas nproc(1)
utliity is totally different which just lists the available number of processors.
Upvotes: 4