Skip to content
Permalink
Browse files
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
  • Loading branch information
vuvova committed Aug 10, 2022
1 parent 9ecdf86 commit 1227428
Showing 1 changed file with 9 additions and 2 deletions.
@@ -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;

1 comment on commit 1227428

@FooBarrior
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Sergei! Finally, somebody made it:)

Please sign in to comment.