7

When a process spawns a subshell, how is the ulimit inherited?

Is it by user, by shell, or a combination?

Specifically, this was found in the context of HP Server Automation jobs failing on some managed AIX devices because of an interaction between the soft and hard ulimits in place. In short, the Agent (which runs as root and generates a subshell when processing commands from SA) was unable to process some jobs because its subshell was hitting a ulimit.

Increasing the ulimit solved the problem, but the question of how the ulimit is inherited, and whether the soft or hard (or both) limits need to be raised is left open.

What is the appropriate answer to this question? It may be AIX-specific, or it may be across Unix/Linux variants - whichever is better.

warren
  • 17,829
  • 23
  • 82
  • 134
  • 1
    Nothing shell specific goes to ulimit. It is a resource limit, users exhaust it. By user, I mean userspace app/process which uses kernel and hardware limit. – Soham Chakraborty Jul 17 '13 at 19:14

1 Answers1

6

The details of implementation vary across *nix platforms , but ulimit is initially set per user, with a default for all users that covers those who lack a specific setting.

In the specific case of AIX, these settings are in /etc/security/limits. Linux uses the slightly-different name /etc/security/limits.conf to do the same job. To be safe, do man ulimit to find the answer for your particular OS.

Monty Harder
  • 633
  • 4
  • 9
  • so - there is no correlation to shell in use? – warren Jul 17 '13 at 16:42
  • I don't understand the question. What "correlation" do you think might exist? – Monty Harder Jul 17 '13 at 17:55
  • if the default shell is bash, for example, and you expect it to be ksh and you don't account for it, there are various environment variables which may (or may not) exist. Also, if it is an interactive session vs headless, some things are different. Hence the clarifying question. – warren Jul 17 '13 at 19:19
  • 1
    ulimit does not have anything to do with the default shell, or whether the session is interactive vs. a cron job, etc. If you need that kind of "correlation", you can implement it by putting a ulimit command in .bashrc that won't be executed by ksh, etc. – Monty Harder Jul 17 '13 at 20:37
  • @warren On Linux, using the bash shell, ulimit is a shell builtin and the ulimits specified within one shell are inherited by processes (including subshells) that are spawned from that shell. From the man page: "ulimit ... Provides control over the resources available to the shell and to processes started by it, on systems that allow such control." – jschultz410 Feb 15 '19 at 03:51