打開core dumps [bash: ulimit: core file size: cannot modify limit: Operation not permitted]

Original Site: https://www.akadia.com/services/ora_enable_core.html

概述(Overview)

In most Linux Distributions core file creation is disabled by default for a normal user. However, it can be necessary to enable this feature for an application (e.g. Oracle). For example, if you encounter an ORA-7445 error in Oracle, then it must be possible to write a core file for the user «oracle».

To enable writing core files you use the ulimit command, it controls the resources available to a process started by the shell, on systems that allow such control.

If you try to enable writing core files, usually you run in the following problem. Normally SSH is used to logon to the server.

ssh oracle@ora-server
$ ulimit -a

core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
file size               (blocks, -f) unlimited
pending signals                 (-i) 1024
max locked memory       (kbytes, -l) 32
max memory size         (kbytes, -m) unlimited
open files                      (-n) 65536
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
stack size              (kbytes, -s) 10240
cpu time               (seconds, -t) unlimited
max user processes              (-u) 16384
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

Now, try (not as user root) to change the core file size to unlimited
在使用ulimit -c unlimited 命令來設置core文件大小爲無限時,出現一下問題。

$ ulimit -c unlimited
-bash: ulimit: core file size: cannot modify limit: Operation not permitted

解決方法(Solution)

1. 檢查ulimit的運行環境(Check Environment for ulimit)

檢查當前用戶下的任何一個shell配置文件,例如在$HOME/.bash_profile$HOME/.bashrc文件中是否設置了ulimit -c 0。如果文件中有該設置,則將該行註釋掉。
(The first step is to check, that you don’t set ulimit -c 0 in any shell configuration files for this user, for example in $HOME/.bash_profile or $HOME/.bashrc. Uncomment it if you have such an entry.)

#
#Do not produce core dumps
#
#ulimit -c 0

2. 對所有用戶(全局)打開Core Dump功能(Globally enable Core Dumps)

這一步驟必須以root用戶來操作,通常是在/etc/security/limits.conf文件中進行設置。(最後一行* soft core unlimited)
(This must be done as user root, usually in /etc/security/limits.conf)

#/etc/security/limits.conf
#
#Each line describes a limit for a user in the form:
#
#<domain> <type> <item> <value>
#
*  soft  core  unlimited

3. 登出當前用戶再登入並設置(Logoff and Logon again and set ulimit)

先在當前用戶查看是否爲unlimited,

ssh oracle@ora-server
$ ulimit -c
0

爲0則表示不輸出core dump文件。
此時先以root用戶進行一次設置(Try to set the limit as user root first)

$ su -
$ ulimit -c unlimited
$ ulimit -c
  unlimited

再以自己的用戶名, 例如oracle, 進行一次設置(Now you can set ulimit also for user oracle

$ su - oracle
$ ulimit -c unlimited
$ ulimit -c
  unlimited

Perhaps the last step number 3 is not necessary, but we have figured out, that this is the way which always work. The core file size limitation is usually also set in different configuration files. If you want to enable cores, you can uncomment them.

In /etc/profile (Redhat)

# No core files by default
# ulimit -S -c 0 > /dev/null 2>&1

In /etc/init.d/functions (Redhat)

# make sure it doesn't core dump anywhere unless requested
# ulimit -S -c ${DAEMON_COREFILE_LIMIT:-0} >/dev/null 2>&1

Now, from this current shell you can generate the core, so check ulimit before.

$ ulimit -a

core file size          (blocks, -c) unlimited
data seg size           (kbytes, -d) unlimited
file size               (blocks, -f) unlimited
pending signals                 (-i) 1024
max locked memory       (kbytes, -l) 32
max memory size         (kbytes, -m) unlimited
open files                      (-n) 65536
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
stack size              (kbytes, -s) 10240
cpu time               (seconds, -t) unlimited
max user processes              (-u) 16384
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章