Core dump is not generated on Ubuntu(14.04 LTS) in some cases.
Sometimes it can be generated. It seems to depend on the program.
Like below ulimit is OK.
$ 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) 15739 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) 15739 virtual memory (kbytes, -v) unlimited file locks (-x) unlimited
I examined where the core dump is generated.
$ sudo sysctl -a | grep core_pattern kernel.core_pattern = |/usr/share/apport/apport %p %s %c %P
On Ubuntu(14.04 LTS) core_pattern uses apport by default.
In case core dump was successfully generated, core dump was generated in current directory.
In case core dump was not generated, an error occurred on apport.
/var/log/apport.log
ERROR: apport (pid 3480) Tue May 12 18:48:31 2015: called for pid 3479, signal 6, core limit 18446744073709551615 ERROR: apport (pid 3480) Tue May 12 18:48:31 2015: ignoring implausibly big core limit, treating as unlimited ERROR: ERROR: apport (pid 3480) Tue May 12 18:48:31 2015: Unhandled exception: Traceback (most recent call last): File "/usr/share/apport/apport", line 357, in <module> (info['ExecutablePath'], info['ProcCmdline'])) File "/usr/share/apport/apport", line 99, in error_log apport.error('apport (pid %s) %s: %s', os.getpid(), time.asctime(), msg) File "/usr/lib/python3/dist-packages/apport/__init__.py", line 44, in error sys.stderr.write(msg % args) UnicodeEncodeError: 'ascii' codec can't encode character '\ufffd' in position 143: ordinal not in range(128) ERROR: apport (pid 3480) Tue May 12 18:48:31 2015: pid: 3480, uid: 0, gid: 0, euid: 0, egid: 0 ERROR: apport (pid 3480) Tue May 12 18:48:31 2015: environment: environ({})
Because an error occurred on apport, core dump was not generated.
This error seems to be Python's UnicodeEncodeError but I'm not sure, so I decided not to use apport in core_pattern.
# echo 'core.%e.%p' > /proc/sys/kernel/core_pattern
$ ulimit -c unlimited $ cat segfault.c #include <stdio.h> int main(void) { char *s = "hello, world!"; *s = 'H'; return 0; } $ gcc -Wall -g -o segfault segfault.c $ ./segfault Segmentation fault (core dumped) $ ls core.segfault.3423 segfault segfault.c
Any configuration changes made using the echo command disappear when the system is restarted.
To make configuration changes take effect after the system is rebooted, edit /etc/sysctl.conf.
Source: E.4. Using the sysctl Command
/etc/sysctl.conf
kernel.core_pattern = core.%e.%p
But when the system is restarted, changes disappear and core_pattern uses apport.
When the system is restarted and apport starts, apport seems to overwrite configuration.
Source: 12.04 - How to permanently edit the core_pattern file? - Ask Ubuntu
To stop this behavior, disable apport and restart the system.
/etc/default/apport
# set this to 0 to disable apport, or to 1 to enable it # you can temporarily override this with # sudo service apport start force_start=1 #enabled=1 enabled=0