Danny Danny - 3 months ago 14
Linux Question

Enable Core dumps for C++ app (called via apache -> Perl -> C++)

I have a web GUI which provides ON/OFF control of a C++ application. The C++ app is called from a perl wrapper who's job it is to keep the program running and restart it if it has stopped.

Clicking the web page button (ultimately) launches

startWrapper.pl
in the background.

The problem is the C++ app crashes with segfault once every few days. I'd like enable core dumps for this background task.

However, everything I've read seems to require a tty and/or login session (eg. ulimit command).

How would I enable core dumps for this background task? Possible to set the configuration from within the C++ source code? Linux config file?

As pseudo code,
startWrapper.pl
(briefly) looks like:

if (is_process_running() )
{
return;
}
else
{
while (1)
{
system("/path/to/c++/application &");

while (1)
{
if (not_running_anymore())
break;
sleep(10);
}
}
}

Answer

Yes, there is a possibility to set system limits from C++ code. Look at getrlimit, setrlimit functions.

#include <sys/resource.h>

rlimit limitValue;
limitValue.rlim_cur = RLIM_INFINITY;
limitValue.rlim_max = RLIM_INFINITY;

setrlimit(RLIMIT_CORE, &limitValue);

RLIMIT_CORE stands for core size RLIM_INFINITY - unlimited rlim_cur - soft limit rlim_max - hard limit

Comments