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.
I was able to get my script to wait for the core dump write to finish by using inotifywait
. See the following snippet:
core_file="core.$app_pid"
core_path=/path/core/file/dir
core_complete="false"
# Setup inotifywait loop to wait until core file has been complety written
inotifywait -e close_write --format '%f' $core_path | while read line; do
echo "File $line was closed"
# Check to see if the line we read was the core file
if [[ "$line" == "$core_file" ]]; then
echo "Core file write complete"
core_complete="true"
fi
done
This so far has seemed to do the trick.