Ubuntu – core file size with ulimit

bashcommand lineulimit

My question is probably not related to Ubuntu in particular, but since my desktop running this OS, I came to this forum.

I am trying to change the core file size using ulimit -c command as follows:

$ ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 7959
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 1024
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

Changing the limitation:

$ ulimit -c unlimited

Observing the result:

$ ulimit -a
core file size          (blocks, -c) unlimited
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 7959
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 1024
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

Indeed the limit is changed.
However, when I open another terminal and check the value, I still see zero value in core file size.

Questions:

  1. Are changes made using ulimit command affect only current process, i.e. in this case the bash?
  2. I launch a program from shell as a fore- or-background process. Does the ulimit change apply for new process ?
  3. How can I make that all user processes are affected with this configuration ?

Best Answer

ulimit is a shell builtin, and thus only affects the current shell, and processes started by that shell:

$ type ulimit
ulimit is a shell builtin

From man ulimit:

The  ulimit  utility  shall  set  or report the file-size writing limit
imposed on files written by the shell and its child processes (files of
any  size  may be read). Only a process with appropriate privileges can
increase the limit.

So, yes, child processes are affected.

To set limits permanently or for all processes, edit /etc/security/limits.conf and reboot. The examples in the manpage are fairly good. You just need to add something like:

username - core unlimited