Jas*_*son 10 osx shell resources ulimit
我想在重新启动时默认启用核心转储生成。
执行:
ulimit -c unlimited
Run Code Online (Sandbox Code Playgroud)
在终端中似乎可以工作,直到计算机重新启动。
想我想出了一些有用的东西。
我使用名为LaunchControl的程序创建了一个名为enable core dumps.plistat的文件,/System/Library/LaunchDaemons其中包含以下内容:
<?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>
Run Code Online (Sandbox Code Playgroud)
具有这些权限:
$ ls -al enable\ core\ dumps.plist
-rw-r--r-- 1 root wheel 582 Dec 30 15:38 enable core dumps.plist
Run Code Online (Sandbox Code Playgroud)
这似乎可以解决问题:
$ launchctl limit core
core unlimited unlimited
$ ulimit -a core
core file size (blocks, -c) unlimited
...
<output snipped>
...
Run Code Online (Sandbox Code Playgroud)
我创建了一个刚刚崩溃的小测试程序:
$ ./a.out
Segmentation fault: 11 (core dumped)
Run Code Online (Sandbox Code Playgroud)
而且,瞧,生成了一个核心转储:
$ # 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
Run Code Online (Sandbox Code Playgroud)