Home

EMFILE

EMFILE is an errno value used on POSIX-compatible systems to signal that a process has reached the limit for the number of open file descriptors. When a process attempts to open a file, create a socket, or otherwise obtain a new descriptor beyond its allowed limit, a system call may fail with EMFILE.

EMFILE refers to the per-process limit on open file descriptors. It is distinct from ENFILE, which indicates

Common causes include long-running servers with many active connections, resource leaks where descriptors are never closed,

Diagnosis and remediation typically involve checking and adjusting limits. The soft and hard limits for the

that
the
entire
system
has
run
out
of
file
descriptors.
A
process
can
encounter
EMFILE
even
if
the
system
as
a
whole
has
free
descriptors
if
the
per-process
table
is
exhausted
or
if
descriptors
are
not
released
promptly.
or
excessive
parallelism
that
exceeds
the
per-process
limit.
It
can
also
occur
after
forking
many
child
processes
without
proper
descriptor
management.
number
of
open
files
can
be
viewed
and
modified
using
tools
like
getrlimit
in
code
or
the
shell
command
ulimit
-n;
current
limits
are
also
visible
in
/proc/self/limits
on
Linux.
If
appropriate,
increase
the
soft
limit,
and,
if
feasible,
raise
the
hard
limit
or
system-wide
limits
such
as
fs.file-max.
In
application
code,
ensure
timely
closure
of
files
and
sockets,
close
descriptors
in
finally
blocks,
and
consider
resource
pooling
or
limiting
concurrent
operations
to
stay
within
allowed
limits.
Understanding
the
distinction
between
EMFILE
and
ENFILE
helps
target
whether
the
issue
is
per-process
or
system-wide.