prevent dumping core file?

K

ken

hello,
i'm writing a c program on a linux system. i'm debugging a segmentation
fault but i don't want it to dump a core file because the memory
footprint of the program is over 300Mb and i don't need it to generate a
300Mb file every time I add a new printf statement to debug the code.

can i do something to prevent it from dumping the core file even when it
seg faults? (is this a unix/linux thing, or a c thing?)

thanks!
ken
 
C

Christopher Benson-Manica

J

Joona I Palaste

ken said:
hello,
i'm writing a c program on a linux system. i'm debugging a segmentation
fault but i don't want it to dump a core file because the memory
footprint of the program is over 300Mb and i don't need it to generate a
300Mb file every time I add a new printf statement to debug the code.
can i do something to prevent it from dumping the core file even when it
seg faults? (is this a unix/linux thing, or a c thing?)

It's a Unix/Linux thing.
 
R

rahul dev

Joona I Palaste said:
It's a Unix/Linux thing.

It is indeed a linux thing. C has nothing to do with dumping a core
file.
The linux kernel writes out a file containing a core image of a
terminated process when certain signals are received. The core image
file is written
in the process's working directory. For more information you may
see the man page of core.
To prevent it from dumping the core file,you may create a directory
named
"core" in your working directory.
 
Z

Zoran Cutura

rahul dev said:
To prevent it from dumping the core file,you may create a directory
named
"core" in your working directory.

or simply set "ulimit -c 0" but that would only be the way it
was meant to be done.
 
N

nrk

rahul said:
It is indeed a linux thing. C has nothing to do with dumping a core
file.
The linux kernel writes out a file containing a core image of a
terminated process when certain signals are received. The core image
file is written
in the process's working directory. For more information you may
see the man page of core.

I seriously doubt if there's a man page for core on a Linux system.
To prevent it from dumping the core file,you may create a directory
named
"core" in your working directory.

A better(?) solution is to use the ulimit (bash) or limit (csh/tcsh)
builtins to set the limit for coredumpsize to 0. To OP: man bash and
search for ulimit to see how this can be done.

-nrk.
 
M

Michel Bardiaux

ken said:
hello,
i'm writing a c program on a linux system. i'm debugging a segmentation
fault but i don't want it to dump a core file because the memory
footprint of the program is over 300Mb and i don't need it to generate a
300Mb file every time I add a new printf statement to debug the code.

can i do something to prevent it from dumping the core file even when it
seg faults? (is this a unix/linux thing, or a c thing?)

thanks!
ken

'limit core 0' in tcsh, or setrlimit() in the program itself. But
Murphy's Law is gonna GET you...
 
R

Richard

(e-mail address removed) wrote...
'limit core 0' in tcsh, or setrlimit() in the program itself. But
Murphy's Law is gonna GET you...

'touch ./core ; chmod 000 ./core' trumps Murphy if '.' is the cwd of
the program dumping core.
 
C

Christopher Benson-Manica

nrk said:
I seriously doubt if there's a man page for core on a Linux system.

FWIW, the NetBSD system I'm on does have a man page for core, so who
knows...?
 
R

rahul dev

nrk said:
I seriously doubt if there's a man page for core on a Linux system.


A better(?) solution is to use the ulimit (bash) or limit (csh/tcsh)
builtins to set the limit for coredumpsize to 0. To OP: man bash and
search for ulimit to see how this can be done.

-nrk

Another way is to symbolically link "core" to "/dev/null".
For those who don't need to search for ulimit in the man pages.
 
D

Dan Pop

In said:
Another way is to symbolically link "core" to "/dev/null".
For those who don't need to search for ulimit in the man pages.

That's a stupid solution: not only does it require the link in every
directory you use for running programs, but it also doesn't prevent the
kernel from generating the code dump, it's just that the core dump gets
lost into the bit bucket and the system resources used to generate it are
simply wasted.

The right thing is the limit builtin command of the modern Unix
shells.

Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top