5

I need to increase the default stack size on Linux. As I know there are usually two ways:

  • ulimit -s size
  • /etc/security/limits.conf

The ulimit method only works as long as I am logged in.

limits.conf will work after a restart.

Is there a possible way to increase the limit without restarting?

Gareth
  • 19,080
Simon
  • 151

4 Answers4

5

What's wrong with editing your .bashrc file to do a ulimit -s size every time you start a terminal session?

Gareth
  • 19,080
Patrick87
  • 281
  • 3
  • 9
1

Linux (and POSIX compatible systems in general) inherit current process limits from existing processes when a new process is started (using fork() or exec()). As a result, you would just need to change the limits for all existing processes that are already running on your system. The config files just define the values for the initial processes after the system has been booted and everything else inherits the current values of parent processes.

Why would you want to increase stack limit of everything? Do all your existing processes immediately require increased stack space for some reason?

If you actually need to change the limits of any given process after that process has already been started, you can do it with command prlimit which uses kernel interface int prlimit(pid_t pid, int resource, const struct rlimit *new_limit, struct rlimit *old_limit) behind the scenes. It requires CAP_SYS_RESOURCE for many use cases so you often need to run that as root in practice.

1

If you want to do this programatically, you can use the setrlimit() function.

0

limits.conf don't need a restart.

It just needs a new session to work.

You need to logout and login.

Inasa Xia
  • 101