Which is the best way to edit the value of RLIMIT_NPROC

My application creates a connection flow. The application is eninng under a non-zero user ID, and sometimes the number of threads exceeds the default value of 1024. I want to edit this number, so I have several options

run as root [a very bad idea, as well as a compromise with securty, so discarding it)

run using setcap as an invalid user and enable CAP_SYS_RESOURCE . then I can add code to my program

      struct rlimit rlp; /* will initilize this later with values of nprocs(maximum number of desired threads)*/
      setrlimit(RLIMIT_NPROC, &rlp);
      /*RLIMIT_NPROC
      *The maximum number of processes (or, more precisely on Linux, threads) that can      
      * created for the real user ID of the
      *calling process.  Upon encountering this limit, fork(2) fails with the error
      *EAGAIN. */

Another thing is to edit /etc/securitylimits.conf, where I can just make an entry for the development user and put the lines, for example.

            @devuser        hard    nproc           20000
            @devuser        soft    nproc           10000

10k . chaning, . , .

, :)

PS: , 1k . ofcource 32 Ram

+4
1

-, , , . , , , . ( ).

, , poll ( 2). . C10K epoll. , libevent libev ..

root (, setuid), ( , TCP/IP) setreuid (2)

Linux...

setuid C, setrlimit (2), setreuid, execve (2) .

+3

Source: https://habr.com/ru/post/1526331/


All Articles