Ullan
Ullan

Reputation: 1017

How to generate core dump file in Linux?

I am trying to generate the core dump file using the below program in Linux.

#include <stdio.h>
#include<iostream>
using namespace std;

int main()
{
     char *temp ="ABCDE";
     int i =0;
     temp[3] ='F';
     for (i =0; i <5; i++)
         printf("% Value is %c\n", temp[i]);

     cout<<"Done"<<endl;
     return 0;
}

I saved the above source code as sample.cpp and build the file using the below command.

     g++ sample.cpp -g -o test

Run the output file "test" which produced the error "Segmentation fault". But it didn't generate the core dump file.

    ./test

I refereed this . Thanks for your help.

Upvotes: 3

Views: 14149

Answers (2)

Miroslav Avramov
Miroslav Avramov

Reputation: 107

Some systems are configured not to write core files by default, since the files can be large and rapidly fill up the available disk space on a system. In the GNU Bash shell the command ulimit -c controls the maximum size of core files. If the size limit is zero, no core files are produced. The current size limit can be shown by typing the following command:

$ ulimit -c 0 If the result is zero, as shown above, then it can be increased with the following command to allow core files of any size to be written:(17)

$ ulimit -c unlimited

Upvotes: 2

Raydel Miranda
Raydel Miranda

Reputation: 14360

The generation of core dump files it is not always enabled. Try with the ulimit command.

Upvotes: 5

Related Questions