Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

How to do that? Without PAM on my GNU/Linux OS the number of open files is 1024 by default and cannot be raised above 4096 (via ulimit -n NNNN command) despiting what is written in /etc/security/limits.conf. So, how does it work without PAM and how to set limits in such case?

===upd===

I decided for myself to use PAM. For those who wants to exceed the hard limit of opened files without PAM, look up for the RLIMIT_NOFILE constant in include/asm-generic/resource.h and INR_OPEN_MAX in include/linux/fs.h which defines the number of 4096 files as hard limit for rlimits. Check also CAP_SYS_RESOURCE which is required to be able to call setrlimit() on a running system to exceed the limit. It seems there is no way to do a system call like setrlimit() in bash, but it may be implemented as a binary executable file. Or you can make a kernel patch.

share|improve this question

1 Answer 1

up vote 4 down vote accepted

Actually it can, you just need to run the syscall (which is what the ulimit command does) with CAP_SYS_RESOURCE capability.

There are two distinct values for every limit: hard and soft. Soft can be raised even by the user up to the hard limit. The hard limit can only be increased with proper privileges (for some resources it cannot be raised over kernel limit). See man getrlimit for more detailed information.

The easy way to do it is to run it by root (i.e. along the lines of: su root; ulimit; su user - first become root, from there change limits, and su back to the appropriate user), the secure way is to have a binary that would have just the aforementioned capability set (see man setcap and man capabilities) and proper access rights.

In your case, the hard limit is 4096, so you can't go beyond that on your own (as a user).

share|improve this answer
    
Thanks for the reply, but actually I have 8192 as a soft limit and 16384 as hard. Look at my limits.conf: pastie.org/pastes/5424844/text Where can I read more about CAP_SYS_RESOURCE and how it is related to setting the number of opened files? I also can’t find manpages for getprlimit on my system, can you suggest a package name or something to search for? The program I want run cannot be started with root privilegies and as you may noticed, there is another user which rights the program is running with. –  tijagi Nov 23 '12 at 22:03
    
If I understood your hint correctly, there is a limit in the kernel, which is 4096 and is used when no PAM installed, so maybe there are some CONFIG_* options that may increase the limits? –  tijagi Nov 23 '12 at 22:03
    
@user685107 sorry, typo in the function name it is getrlimit, I have updated the answer. limits.conf is only used by PAM, it has no effect otherwise. –  peterph Nov 23 '12 at 22:21
    
@user685107 as for the 4096, I believe this is the default hard limit for number of open files. I'm successfully changing to 16k often with the su - ulimit - su idiom. –  peterph Nov 23 '12 at 22:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.