How do I set 'max threads per process' ulimit for non-root user?

Ulimit man page suggests -r option will set this but it only appears to be valid for the root user and there is no equivalent for setting it via /etc/security/limits?

Any ideas?


Solution 1:

You said AIX, but in the case of linux I think it would just be the -u limit switch. In Linux this states 'processes', but with bash, ulimit is just a interface to the setrlimit system call. This can be seen by running strace bash -c 'ulimit -u 10' which returns:

setrlimit(RLIMIT_NPROC, {rlim_cur=10, rlim_max=10}) = 0

The man page for setrlimit states:

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. Upon encountering this limit, fork(2) fails with the error EAGAIN.

So maybe it is the same for AIX? This link states: "AIX does not define RLIMIT_NPROC or RLIMIT_MEMLOCK resources.", but you might be able to find a more definitive answer on developerworks.

For the permissions issue, the solution may be to set the limit with root, and then su to the user you need to increase the limit for. I have had to do this for other resource limits in the past, for example, max open files. The limits.conf was not applied so I had do use sudo or su from root, and then the limit gets inherited.