How to avoid core dump when exiting the process in linux/unix

Sometimes in an application, we want to exit the process forcefully (no graceful termination), but do not want the core dump to be generated. One example could be a service that is being monitored by “monit” and if killed is restarted automatically by monit. If this service has multiple threads, it might happen that calling “exit(0)” from main thread will make the memory invalid which might still be being accessed by the threads. This will cause SIGSEGV (Segmentation fault) and will generate core dump. To avoid that, rather than calling exit(0) from the main thread, raise SIGKILL signal i.e. “raise(SIGKILL)”. SIGKILL signal does not generate core dump and will also terminate the process instantly.

This entry was posted in Uncategorized and tagged , , , , , , , , , . Bookmark the permalink.

Leave a comment