3

I have a situation here, a few days back I was able to see a core- dump file on my target board, I have enabled the core-dump generation by adding "ulimit -c unlimited" to my /etc/profile.

But then someone told me, this will only take affect for program launched from a login shell, not for processes/services started by systemd, etc. and the ulimits are set at another location.

So I changed /etc/limits file and added ulimit -c unlimited line, but still I could not see core-dump file.

I am running kill -9 $$ to generate segmentation fault and it in turn will generate core-dump file as it was doing earlier.

We tried changing "/proc/sys/kernel/core_pattern" file and running ulimit -c unlimited explicitly but this was not enough.

Where we are going wrong?

artless noise
  • 21,212
  • 6
  • 68
  • 105
Amit Singh Tomar
  • 8,380
  • 27
  • 120
  • 199

4 Answers4

9

kill -9 will not generate a core file. The command kill -l gives a list of supported signals. kill -6 or kill -SIGABRT should produce a core file. As well as most other signals such as kill -BUS, kill -SEGV, etc.

artless noise
  • 21,212
  • 6
  • 68
  • 105
5

kill -11 always works for me. 11 is SIGSEGV (invalid memory reference)

Danish Rizvi
  • 81
  • 1
  • 3
  • But that is a bad idea. Some weird programs might *catch* `SIGSEGV`; `SIGABRT` is much more conventional, and the few programs catching it knows about it meaning. – Basile Starynkevitch Jul 18 '15 at 06:51
2

You have to first off enable user limits settings to ensure that core files can be created.

ulimit -c unlimited

Application user must run as and before you start the application in the same session. This setting is inherited by the application, so what ever the ulimit is set as before starting the application is what the ulimit setting will be for the application (unless a start script changes it).

josliber
  • 43,891
  • 12
  • 98
  • 133
Amit
  • 31
  • 1
0

In addition of the other answers, you might also use gcore(1) to generate a core dump of some running process.

But if using kill(1) command (or the underlying kill(2) syscall, e.g. from some ad-hoc program), I recommend using SIGABRT (the signal that abort(3) send to itself after unblocking it), as documented in the signal(7).

Beware, a program can usually forbid core dumping, e.g. by calling setrlimit(2) with RLIMIT_CORE set to 0 or handling or ignoring some signals (with e.g. sigaction(2)...).

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547