我的问题可能与 Ubuntu 没有特别关系,但由于我的桌面运行这个操作系统,所以我来到了这个论坛。
ulimit -c
我正在尝试使用以下命令更改核心文件大小:
$ 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
改变限制:
$ ulimit -c unlimited
观察结果:
$ 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
确实限制已更改。但是,当我打开另一个终端并检查该值时,我仍然看到核心文件大小为零。
问题:
- 使用命令所做的更改是否
ulimit
仅影响当前进程,即在这种情况下bash
? - 我从 shell 启动一个程序作为前台或后台进程。更改是否
ulimit
适用于新进程? - 如何使所有用户进程都受到此配置的影响?
答案1
ulimit
是 shell 的内置命令,因此只影响当前 shell 以及由该 shell 启动的进程:
$ type ulimit
ulimit is a shell builtin
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.
因此,是的,子进程确实受到了影响。
要永久设置限制或为所有进程设置限制,请编辑/etc/security/limits.conf
然后重启。手册页中的示例相当不错。您只需添加类似以下内容的内容:
username - core unlimited