Skip to content

Commit

Permalink
my_safe_process: try to kill the process softly first
Browse files Browse the repository at this point in the history
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
  • Loading branch information
vuvova committed Aug 9, 2022
1 parent 68ce7ff commit 8675755
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion mysql-test/lib/My/SafeProcess/safe_process.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,12 @@ static int kill_child(bool was_killed)
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 (!waitpid(child_pid, &status, WNOHANG))
kill(-child_pid, SIGKILL);
}

pid_t ret_pid= waitpid(child_pid, &status, 0);
if (ret_pid == child_pid)
Expand Down

0 comments on commit 8675755

Please sign in to comment.