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);

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

int
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
#include
int main(int argv,char *argc) {
sleep(10000);
}

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
#ulimit
# -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
/cores
/cores/core.5018
/cores/core.5075
/cores/core.5097
/cores/core.5108
/cores/core.5121
/cores/core.5155
/cores/core.5166

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

Comments

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