summaryrefslogtreecommitdiff
path: root/mysql-test/lib
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2022-06-23 12:59:31 +0200
committerSergei Golubchik <serg@mariadb.org>2022-08-10 09:14:17 +0200
commit122742897b47a19c85b1a5e9932ab3a8c2a4134e (patch)
treeb05fefeca7a96a0c398c5f3ebe348548ba490139 /mysql-test/lib
parent9ecdf860ce12255bd79869a4f3ac9f6784fe74cf (diff)
downloadmariadb-git-122742897b47a19c85b1a5e9932ab3a8c2a4134e.tar.gz
my_safe_process: try to kill the process softly first
first SIGTERM and if the process didn't die in 10 seconds, SIGKILL it. This allows various tools like `rr`, `gcov`, `gprof`, etc to flush their data to disk properly
Diffstat (limited to 'mysql-test/lib')
-rw-r--r--mysql-test/lib/My/SafeProcess/safe_process.cc11
1 files changed, 9 insertions, 2 deletions
diff --git a/mysql-test/lib/My/SafeProcess/safe_process.cc b/mysql-test/lib/My/SafeProcess/safe_process.cc
index 4d0d1e2a3a0..dcf9491d2d6 100644
--- a/mysql-test/lib/My/SafeProcess/safe_process.cc
+++ b/mysql-test/lib/My/SafeProcess/safe_process.cc
@@ -140,13 +140,20 @@ void handle_core(pid_t pid __attribute__((unused))) {}
static int kill_child(bool was_killed)
{
int status= 0;
+ pid_t ret_pid= 0;
message("Killing child: %d", child_pid);
// Terminate whole process group
if (! was_killed)
- kill(-child_pid, SIGKILL);
+ {
+ kill(-child_pid, SIGTERM);
+ sleep(10); // will be interrupted by SIGCHLD
+ if (!(ret_pid= waitpid(child_pid, &status, WNOHANG)))
+ kill(-child_pid, SIGKILL);
+ }
- pid_t ret_pid= waitpid(child_pid, &status, 0);
+ if (!ret_pid)
+ ret_pid= waitpid(child_pid, &status, 0);
if (ret_pid == child_pid)
{
int exit_code= 1;