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?
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: %s\nWarning: core dumps may be truncated or non-existant\n", strerror(errno));
Credit goes here: http://adamrosenfield.com/blog/2010/04/23/dumping-core/
if you want to check your current limit for your process than
struct rlimit v; //you can decelare any variable
getrlimit(RLIMIT_CORE, &v);
printf("softlimit=%d hardlimit=%d \n",v.rlim_cur,v.rlim_max);
if you want to set new limit than use below code
///////////////////// set limit //////////////////////////////
lets make it simple
struct rlimit v;
v.rlim_cur = 0 ; //if you do not want the core dump file
/* v.rlim_cur=RLIM_INFINITY; //set maximum soft limit of the file(unlimited) */
v.rlim_max = RLIM_INFINITY; //for reference to the soft limit(unlimited)
setrlimit(RLIMIT_CORE, &v);
A value of rlim_cur
is between 0 and infinity means that core dumps will be generated and truncated to the specified size. This risks creating an incomplete core dump
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With