summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkos Kiss <akiss@inf.u-szeged.hu>2017-10-20 09:52:52 +0200
committerGiampaolo Rodola <g.rodola@gmail.com>2017-10-20 09:52:52 +0200
commit548656a636da14636c44fd1ce64c677dbcb6e15d (patch)
tree94f774808c94407d6b31199f524cdf16336dcac0
parent3e5e9b780c9e2809f7552f6218e5ae86cbd35e28 (diff)
downloadpsutil-548656a636da14636c44fd1ce64c677dbcb6e15d.tar.gz
Terminate Windows processes with SIGTERM code rather than 0 (#1150)
If the TerminateProcess WinAPI function is called with 0, then the exit code of the terminated process (e.g., observed by its parent) will be 0. However, this is usually associated with successful execution. Any other exit code could be used to signal forced termination, but perhaps the value of SIGTERM is the most meaningful.
-rw-r--r--psutil/_psutil_windows.c3
-rwxr-xr-xpsutil/tests/test_process.py10
2 files changed, 7 insertions, 6 deletions
diff --git a/psutil/_psutil_windows.c b/psutil/_psutil_windows.c
index bca6cac0..d908a1c7 100644
--- a/psutil/_psutil_windows.c
+++ b/psutil/_psutil_windows.c
@@ -25,6 +25,7 @@
#include <wtsapi32.h>
#include <Winsvc.h>
#include <PowrProf.h>
+#include <signal.h>
// Link with Iphlpapi.lib
#pragma comment(lib, "IPHLPAPI.lib")
@@ -349,7 +350,7 @@ psutil_proc_kill(PyObject *self, PyObject *args) {
}
// kill the process
- if (! TerminateProcess(hProcess, 0)) {
+ if (! TerminateProcess(hProcess, SIGTERM)) {
err = GetLastError();
// See: https://github.com/giampaolo/psutil/issues/1099
if (err != ERROR_ACCESS_DENIED) {
diff --git a/psutil/tests/test_process.py b/psutil/tests/test_process.py
index bd13c2d2..fa07f5a9 100755
--- a/psutil/tests/test_process.py
+++ b/psutil/tests/test_process.py
@@ -151,7 +151,7 @@ class TestProcess(unittest.TestCase):
if POSIX:
self.assertEqual(code, -signal.SIGKILL)
else:
- self.assertEqual(code, 0)
+ self.assertEqual(code, signal.SIGTERM)
self.assertFalse(p.is_running())
sproc = get_test_subprocess()
@@ -161,7 +161,7 @@ class TestProcess(unittest.TestCase):
if POSIX:
self.assertEqual(code, -signal.SIGTERM)
else:
- self.assertEqual(code, 0)
+ self.assertEqual(code, signal.SIGTERM)
self.assertFalse(p.is_running())
# check sys.exit() code
@@ -207,8 +207,8 @@ class TestProcess(unittest.TestCase):
# to get None.
self.assertEqual(ret2, None)
else:
- self.assertEqual(ret1, 0)
- self.assertEqual(ret1, 0)
+ self.assertEqual(ret1, signal.SIGTERM)
+ self.assertEqual(ret1, signal.SIGTERM)
def test_wait_timeout_0(self):
sproc = get_test_subprocess()
@@ -227,7 +227,7 @@ class TestProcess(unittest.TestCase):
if POSIX:
self.assertEqual(code, -signal.SIGKILL)
else:
- self.assertEqual(code, 0)
+ self.assertEqual(code, signal.SIGTERM)
self.assertFalse(p.is_running())
def test_cpu_percent(self):