Ubuntu 22.04 - How to store Core Dump files in same directory as executable

2.3k Views Asked by At

I am using Ubuntu 22.04.

cat /proc/sys/kernel/core_pattern
|/lib/systemd/systemd-coredump %P %u %g %s %t 9223372036854775808 %h

As far as I understand I am using systemd-coredump to generate coredump files when my C++ program crashes. However the coredump files are stored here /var/lib/systemd/coredump

I would like to change the coredump storing location to be at the same place where the executable is.

This thing drives me crazy, I red alot over stackoverflow but all info looks to be for older versions of Ubuntu not for 22.04.

Is there anyway I can achieve that?

P.S. I have uninstalled apport by running sudo apt-get remove apport

1

There are 1 best solutions below

0
On

So, this was a rabbit hole...

Try doing things in this checklist:

  • run ulimit -s unlimited so that you have no memory limit of how large the core dump needs to be
  • Then run sudo bash -c "sudo bash -c "echo 'core.%p.%e.%t.%h' > /proc/sys/kernel/core_pattern" which will set the core dump location to the local directory with the pattern core.%p.%e.%t.%h
  • This will however not persist after reboot. You may find the reason using this command sudo sysctl --system which shows kernel parameters being set by each file. In my case, I had a line which said Applying /usr/lib/sysctl.d/50-coredump.conf which was changing my coredump pattern to go through systemd. So I edited this file so that line would then have kernel.core_pattern=core.%e.%p.%h.%t and this fixed is so that saving the core dump within the same folder now persists after reboot as well.