具有ulimit的核心文件大小


12

我的问题可能与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

确实,限制已更改。但是,当我打开另一个终端并检查该值时,我仍然看到核心文件大小为零。

问题:

  1. 使用ulimit命令进行的更改是否仅影响当前进程,即在这种情况下bash
  2. 我从外壳程序启动程序是作为前台或后台进程。ulimit更改是否适用于新流程?
  3. 如何使所有用户进程受此配置影响?

1
您在询问之前是否进行了搜索?serverfault.com/questions/637212/increasing-ulimit-on-centos
kenn

Answers:


10

ulimit 是内置的shell,因此仅影响当前shell,以及由该shell启动的进程:

$ type ulimit
ulimit is a shell builtin

来自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.

因此,是的,子进程受到影响。

要永久或为所有进程设置限制,请编辑/etc/security/limits.conf并重新启动。手册页中的示例相当不错。您只需要添加以下内容:

username - core unlimited

谢谢。通过manpages.ubuntu.com/manpages/bionic/man1/ulimit.1posix.htmlulimit除了是bash内置命令外,还是外部命令吗?
蒂姆(Tim)

@Tim引用链接到的页面:“由于ulimit影响当前的Shell执行环境,因此始终将其作为Shell常规内置项提供。”
muru
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.