From man setrlimit
RLIMIT_NPROC The maximum number of processes (or, more precisely, on Linux, threads) that can be created for the real user ID of the calling process. When faced with this limit, fork (2) fails with error EAGAIN.
As you can see, setrlimit can set restrictions for the user of the calling process. Thus, it can set restrictions for the user through the calling process of that user.
To your second question, in some cases, the kernel does not allow the process to exceed its limit in the first place. In the above example, fork() itself fails, rather than killing the calling process after allocating more resources. In some cases, for example, when using the CPU, when the process exceeds its SOFT_LIMIT , a SIGXCPU message is sent. And when he exceeds his HARD_LIMIT , SIGKILL sets off
source share