Home

RLIMITSTACK

RLIMITSTACK (RLIMIT_STACK in POSIX) is a resource limit that defines the maximum size of a thread’s stack. It is part of the suite of RLIMIT resources used to control a process’s memory usage and is accessed through system interfaces such as getrlimit and setrlimit.

The stack for a thread grows downward as the thread allocates stack frames. The limit restricts how

Setting and querying the limit are done with the rlimit structure and the functions getrlimit and setrlimit.

Default values for RLIMIT_STACK vary by operating system and architecture. On many Linux systems, the main thread

See also RLIMIT_AS, setrlimit, getrlimit, and pthreads.

large
that
per-thread
stack
can
become.
If
a
thread
attempts
to
grow
beyond
the
soft
limit,
the
growth
is
constrained
and,
when
the
limit
is
reached,
memory
access
faults
can
occur,
typically
resulting
in
a
signal
such
as
a
segmentation
fault
that
terminates
the
offending
thread
or
process.
The
soft
limit
(rlim_cur)
may
be
raised
up
to
the
hard
limit
(rlim_max);
increasing
the
hard
limit
generally
requires
privileges.
In
practice,
the
hard
limit
can
often
be
lowered
by
a
non-privileged
user,
while
raising
it
usually
requires
administrative
permission.
The
structure
contains
rlim_cur
(soft
limit)
and
rlim_max
(hard
limit).
A
value
of
RLIM_INFINITY
denotes
no
limit,
though
actual
applicability
may
be
bounded
by
address
space
constraints
of
the
operating
system.
stack
is
on
the
order
of
a
few
to
several
tens
of
megabytes,
commonly
with
a
soft
limit
around
8
MB.
The
limit
is
an
important
consideration
for
applications
with
deep
or
intensive
recursion,
multithreaded
programs,
and
security
hardening,
since
overly
large
or
misconfigured
stacks
can
lead
to
resource
exhaustion
or
instability.