Blob Blame History Raw
From 42275cd83f11846da32e62b940ac238258f49ae4 Mon Sep 17 00:00:00 2001
From: Derek Higgins <derekh@redhat.com>
Date: Wed, 18 Mar 2015 15:04:22 +0000
Subject: [PATCH] Kill the entire process group when a command  times out

In cases where the command being executed spawns subcommands
we need to ensure they are all killed, so that the timeout
occurs when it should instead of waiting for the subprocesses to exit.
---
 sh.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/sh.py b/sh.py
index fb0f5fe..d461a1a 100644
--- a/sh.py
+++ b/sh.py
@@ -1531,7 +1531,9 @@ class OProc(object):
     def signal(self, sig):
         self.log.debug("sending signal %d", sig)
         try:
-            os.kill(self.pid, sig)
+            # Kill the entire process group as the command may have
+            # spawned subprocesses we don't want left around
+            os.killpg(os.getpgid(self.pid), sig)
         except OSError:
             pass
 
-- 
2.5.0