Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a long running process that is eventually going to hit the max open file limit. I know how to change that after it fails, but is there a way to change that for the running process, from the command line?

share|improve this question

5 Answers 5

On newer kernels (2.6.32+) you can change this at runtime with /proc//limits:

cd /proc/7671/
[root@host 7671]# cat limits  | grep nice
Max nice priority         0                    0                    
[root@host 7671]# echo -n "Max nice priority=5:6" > limits
[root@host 7671]# cat limits  | grep nice
Max nice priority         5                    6                    
share|improve this answer
    
That rules! Had no idea you could write to the limits file. –  clee May 15 '12 at 22:11
4  
doesn't work for me on ubuntu 12.04 –  Poma Jul 10 '12 at 7:06
3  
This does not work on my 3.2 kernel. I guess your distribution has a specific unofficial patch for this because I see no trace of this patch in the kernel's fs/proc/base.c. –  Totor Apr 19 '13 at 13:43

You can try ulimit man ulimit with the -n option however the mag page does not most OS's do not allow this to be set.

You can set a system wide file descriptions limit using sysctl -w fs.file-max=N and make the changes persist post boot up in /etc/sysctl.conf

However I would also suggest looking at the process to see if it really needs to have so many files open at a given time, and if you can in fact close some files down and be more efficient in the process.

share|improve this answer
    
The open file thing is a bug, but I haven't been able to figure it out. While I'd love to do so, production periodically crashes mid-day. –  kāgii Nov 12 '10 at 15:57

As documented here (http://karelzak.blogspot.de/2012/01/prlimit1.html) .. the prlimit command, to be introduced with util-linux 2.21 will allow you to read and change the limits of running processes.

This is a followup to the writable /proc//limits, which was not integrated in mainline kernel. This solution should work.

If you don't have prlimit(1) yet, you can find the code to a minimalistic version in the prlimit(2) manpage.

share|improve this answer

The process could change its own soft limits if programmed to do so (or if you manage to hack it), but it can't raise its hard limits unless it has the CAP_SYS_RESOURCE capability. You can inspect the limits at runtime in /proc/$pid/limits .

share|improve this answer

On newer version of util-linux-ng you can use prlimit command, for more infomation read this link http://superuser.com/questions/404239/setting-ulimit-on-a-running-process

share|improve this answer

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.