Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
avoid leaving dangling children by killing spawned processes recursively
  • Loading branch information
Jalle19 authored and perexg committed Apr 9, 2015
1 parent 02427fe commit 14f03b8
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/spawn.c
Expand Up @@ -299,7 +299,8 @@ spawn_kill(pid_t pid, int sig)
if(s->pid == pid)
break;
if (s) {
r = kill(pid, sig);
/* kill the whole process group */
r = kill(-pid, sig);
if (r < 0)
r = -errno;
}
Expand Down Expand Up @@ -502,8 +503,14 @@ spawn_and_give_stdout(const char *prog, char *argv[], char *envp[],
close(fd[1]);

*rd = fd[0];
if (pid)
if (pid) {
*pid = p;

// make the spawned process a session leader so killing the
// process group recursively kills any child process that
// might have been spawned
setpgid(p, p);
}
return 0;
}

Expand Down

0 comments on commit 14f03b8

Please sign in to comment.