Linux – how to limit the number of simultaneous processes per user in the system

debianlinuxSecurity

yep, i know that question was asked many times, but unfortunately i didn't find the complete answer on it.

so, how to limit the number of simultaneous processes per user?

i found two solutions:

  1. using pam_limits. in that case i need to configure /etc/security/limits.conf file. unfortunately, this solution works only for pam aware applications, that is it's not universal.

  2. using ulimit called from $HOME/profile. unfortunately it doens't work in all cases too. i tried to set "ulimit -u 100" and then launched in the same shell "stress –vm 200 –vm–bytes 100". application was successfully launched and i got more than 200 processes under user root.

i need to build a robust system, so solutions which work only in some cases are inappropriate.

Best Answer

A kernel security patch grsecurity has a feature called Enforce RLMIT_NPROC on execs. When enabled, it enforces per-user limits to be system-wide instead of per-login (or worse, as you have observed).