10

I want to enable core dump generation by default upon reboot.

Executing:

ulimit -c unlimited

in a terminal seems to work until the computer is rebooted.

0

2 Answers 2

5

Think I figured out something that works.

I used a program called LaunchControl to create a file called enable core dumps.plist at /System/Library/LaunchDaemons with the following contents:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>GroupName</key>
    <string>wheel</string>
    <key>InitGroups</key>
    <true/>
    <key>Label</key>
    <string>core dumps launchctl</string>
    <key>ProgramArguments</key>
    <array>
        <string>launchctl</string>
        <string>limit</string>
        <string>core</string>
        <string>unlimited</string>
        <string>unlimited</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>UserName</key>
    <string>root</string>
</dict>
</plist>

with these permissions:

$ ls -al enable\ core\ dumps.plist 
-rw-r--r--  1 root  wheel  582 Dec 30 15:38 enable core dumps.plist

and this seemed to do the trick:

$ launchctl limit core
    core        unlimited      unlimited 
$ ulimit -a core
core file size          (blocks, -c) unlimited
...
<output snipped>
...

I created a little test program that just crashes:

$ ./a.out 
Segmentation fault: 11 (core dumped)

And, voila, a core dump was generated:

$ # ls -al /cores/
total 895856
drwxrwxr-t@  3 root  admin        102 Dec 30 15:55 .
drwxr-xr-x  31 root  wheel       1122 Oct 18 10:32 ..
-r--------   1 root  admin  458678272 Dec 30 15:55 core.426
0

To apply persistent shell limits, you need to add ulimit commands into respective startup shell files.

For individual users, use: ~/.bashrc or ~/.bash_profile files.

For all users, use: /etc/bashrc file.

Suggested lines to add:

# Changes the ulimit limits.
ulimit -Sn 4096      # Increase open files.
ulimit -Sl unlimited # Increase max locked memory.

To change system resource limits via launchctl, see: How to persist ulimit settings in macOS?

Not the answer you're looking for? Browse other questions tagged .