I launch my program from .sh file (for simplicity let's say it's content is just ./myprogram). For some unknown reason the program generates large core.* files. What should I add in my .sh file so that these files are being deleted while my program is running?
1 Answer
core
files are written for post mortem of crashed processes, you must find out what is happening (a segmentation fault or other crash might signal a serious security vulnerability!).
As the file is written after the program crashed, they can safely be removed at any time. In any case, if you delete a file that is being held open by a process, the filesystem entry will be removed, but the process isn't affected at all.
-
Of course something should be fixed with the program. I should have formulated my question as "How to delete files (not necessarily core files) while the program is running". ./myprogram; while(true) ; do rm -f core.*;done launches an infinite loop . I was expecting answers related to find a way around this. Nov 14, 2015 at 16:40
-
Move
./myprogram
to inside the while loop seems like the trivial fix here... or remove the while loop. If you really meant "delete files while program is running" then put the program in the background with&
and dowhile kill -0 $!; do rm -f core.*; done
. But this is still solving the wrong problem: prevent the garbage files form being created in the first place!– wurtelNov 16, 2015 at 14:04
rm -f core.*
somewhere in your code?ulimit -c 0
or such to limit the coredump size, or fix the buggy code causing the coredumps...