How to create a core dump

>gcc -o null.exe null.c ; null.exe
//c program that I found on the net that will cause a core dump
//file null.c
int a (int *p);

main (void)
int *p = 0; /* null pointer */
return a (p);

a (int *p)
int y = *p;
return y;
Here are two other ways to create core dumps
>gcc -o crash.exe crash.c ; ./crash.exe
//file crash.c
int main(int argv,char *argc) {
int *numdie;
numdie[23] = 23;

>gcc -o sleep.exe sleep.c | ./sleep
//file sleep.c
int main(int argv,char *argc) {

In another terminal
>ps aux | grep sleep.exe
replace pid with the pid you find from the previous command
pid will be a number in the second column
>kill -SIGV pid

if you see an error like
No core dump was created
>Bus error
An error like this means a core dump was created
>Bus error (core dumped)

>ulimit -c #will print the current core file max size
>ulimit -c unlimited to make it unlimited
# -c The maximum size of core files created.
Usually the core files are created in the same directory as the program, which is usually the present working directory pwd.

Mac OSX stores the core dumps in /cores

To change the location of the
>sysctl -a | grep kern.corefile
Use a command like the following to change it
>sysctl -w kern.corefile=/cores/core.%P


d3ck4 said…
thx.. im macs newb.. this help me just now

Popular posts from this blog

Vim vi how to reload a file your editing