Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find out when core dump is finished

I am working on a bash script that collects various diagnostic information on a CentOS server and packages them up so that they can be sent to our company for analysis. As part of this script, I check to see if the company's application is responsive. If it is not, I trigger a core dump of the application process:

kill -6 $app_pid

This command will cause a process core dump to be written for the pid $app_pid. However, I need a way to wait until the core dump generation is finished. Otherwise, I can create corrupt diagnostics packages due to the incomplete core dump.

I am hoping to do this check using the default centos packages but am also open to installing additional packages if I must.

like image 235
Andrew Avatar asked Oct 15 '25 07:10

Andrew


1 Answers

The mechanism that gives you the most control is to specify a pipeline in /proc/sys/kernel/core_pattern. This will let a program of your choosing be executed when a coredump is created, so that program can be 100% certain that it has the full dump when (and only when!) its stdin file descriptor is in the EOF condition. See the section "Piping core dumps to a program" in man 5 core.

If you're using systemd (as modern versions of CentOS do), the systemd-coredump program will already configure itself in this way. systemd-coredump renames files from a temporary name when compression is complete, so it already does the work of ensuring that you only have a complete coredump ready to log.

Thus, if you have a file named of the form:

/var/lib/systemd/coredump/core.*.lz4

(or otherwise with the extension of your chosen compression algorithm), you can already be assured that it's complete, as that file was written and had its permissions set before it was renamed to that final name.

like image 142
Charles Duffy Avatar answered Oct 16 '25 23:10

Charles Duffy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!