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?

  • Can't you simply add a rm -f core.* somewhere in your code?
    – Kira
    Nov 13, 2015 at 18:35
  • 6
    Or possibly ulimit -c 0 or such to limit the coredump size, or fix the buggy code causing the coredumps...
    – thrig
    Nov 13, 2015 at 18:39
  • 2
    You should fix your program so it doesn't generate a core dump.
    – ott--
    Nov 13, 2015 at 18:46

1 Answer 1


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.
    – alxprogger
    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 do while 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!
    – wurtel
    Nov 16, 2015 at 14:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.