Skip to content
Advertisement

Turn on core/crash dumps programmatically

I know I can run “ulimit -c unlimited”

In the shell to turn on core dumps for the current user. What I am wondering is how can I do this programmatically from C?

I see there is a ulimit call, but it’s been deprecated in favour of get/setrlimit. What I want to know is what is the equivalent call to setrlimit that would allow crash dumps to be generated?

Advertisement

Answer

I found a working solution. The core files are now being created.

struct rlimit core_limit;
core_limit.rlim_cur = RLIM_INFINITY;
core_limit.rlim_max = RLIM_INFINITY;

if (setrlimit(RLIMIT_CORE, &core_limit) < 0)
    fprintf(stderr, "setrlimit: %snWarning: core dumps may be truncated or non-existantn", strerror(errno));

Credit goes here: http://adamrosenfield.com/blog/2010/04/23/dumping-core/

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement