summaryrefslogtreecommitdiff
path: root/process-posix.c
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2021-04-17 10:54:22 -0400
committerLeo Tenenbaum <pommicket@gmail.com>2021-04-17 10:54:22 -0400
commit6ad4547b465a83f7f3681d464110288895093944 (patch)
tree6d9e37e31c1c9930e8061bb070f10fe37d8d8780 /process-posix.c
parentb8c5d256646130067cc6f2d4db676dc2173522ac (diff)
fix process_kill on posix
Diffstat (limited to 'process-posix.c')
-rw-r--r--process-posix.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/process-posix.c b/process-posix.c
index 1236323..f35017f 100644
--- a/process-posix.c
+++ b/process-posix.c
@@ -14,12 +14,15 @@ bool process_run(Process *proc, char const *command) {
memset(proc, 0, sizeof *proc);
bool success = false;
-
int pipefd[2];
if (pipe(pipefd) == 0) {
pid_t pid = fork();
if (pid == 0) {
// child process
+ // put child in its own group. it will be in this group with all of its descendents,
+ // so by killing everything in the group, we kill all the descendents of this process.
+ // if we didn't do this, we would just be killing the sh process in process_kill.
+ setpgid(0, 0);
// send stdout and stderr to pipe
dup2(pipefd[1], STDOUT_FILENO);
dup2(pipefd[1], STDERR_FILENO);
@@ -64,7 +67,7 @@ long long process_read(Process *proc, char *data, size_t size) {
}
void process_kill(Process *proc) {
- kill(proc->pid, SIGKILL);
+ kill(-proc->pid, SIGKILL); // kill everything in process group
// get rid of zombie process
waitpid(proc->pid, NULL, 0);
close(proc->pipe);