# [EMFILE] Too many open files



## mjr88 (Feb 5, 2013)

Hi all,

We're getting this error (24: Too many open files) in a proxy server that we handle while trying to open a file.

Manpage for open() states that it returns this error when it reaches the max open files limit for the process, but we have these numbers:


```
# sysctl kern.maxfiles kern.maxfilesperproc kern.openfiles
kern.maxfiles: 1048576
kern.maxfilesperproc: 1048576
kern.openfiles: 58428
```

As you can see, we have less than 60 thousand open files at kernel level, and probably 99% of these is opened by our proxy process. So, how can the system return EMFILE when we are using mere 5% of the max limit?

I'm a little confused here :\. Any clues?


----------



## chatwizrd (Feb 5, 2013)

Check *ulimit -n*. You can change the defaults in /etc/login.conf.

login.conf()


----------



## mjr88 (Feb 5, 2013)

chatwizrd said:
			
		

> Check ulimit -n



Hi, chat. Thanks for answering.

Unfortunatelly, i did it already:


```
# ulimit -n
1048576
# ulimit -Hn
1048576
# ulimit -Sn
1048576
```

I've also tried the getrlimit function from inside the process (written in C):


```
struct rlimit rl;
getrlimit(RLIMIT_NOFILE, &rl);
```

Both rl.rlim_cur and rl.rlim_max returns 1048576.

Don't know what else to try .


----------



## mjr88 (Feb 5, 2013)

chatwizrd said:
			
		

> You can change the defaults in /etc/login.conf
> 
> login.conf()



Yeah, this is what we have made so far:


```
default:\
...
        :cputime=unlimited:\
        :datasize=unlimited:\
        :stacksize=unlimited:\
        :memorylocked=unlimited:\
        :memoryuse=unlimited:\
        :filesize=unlimited:\
        :coredumpsize=unlimited:\
        [B]:openfiles=unlimited:[/B]\
        :maxproc=unlimited:\
        :sbsize=unlimited:\
        :vmemoryuse=unlimited:\
        :swapuse=unlimited:\
        :pseudoterminals=unlimited:\
...
```

The process is running as root, and still getting the error


----------



## LuizBiazus (Feb 6, 2013)

i have interesting in this topic too... seems like a FreeBSD bug doesn't it?


----------



## densone (Apr 28, 2022)

@mjr68 Did you ever solve this? I’m running into a similar issue.


----------



## SirDice (Apr 28, 2022)

User hasn't been seen for 6 years, this thread is almost 10 years old. Open a new thread with your issue.


----------

