summaryrefslogtreecommitdiff
path: root/xmake/core/base/process.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2020-02-07 00:07:52 +0800
committerruki <[email protected]>2020-02-07 22:45:57 +0800
commit5cd2e08845765fb1e21b72f22e2707f7e8233b7b (patch)
treedb500c9cc555daa553baad32b04a5368a39bc799 /xmake/core/base/process.lua
parent7ba4dd03abc93f7faff3afa9968f8c8e7ce478c6 (diff)
kill all pending process after exiting
Diffstat (limited to 'xmake/core/base/process.lua')
-rw-r--r--xmake/core/base/process.lua21
1 files changed, 21 insertions, 0 deletions
diff --git a/xmake/core/base/process.lua b/xmake/core/base/process.lua
index 20cfbe02c..51fe02ecd 100644
--- a/xmake/core/base/process.lua
+++ b/xmake/core/base/process.lua
@@ -47,6 +47,7 @@ function _subprocess.new(name, proc)
subprocess._NAME = name
subprocess._PROC = proc
setmetatable(subprocess, _subprocess)
+ process._openlist()[subprocess:cdata()] = subprocess
return subprocess
end
@@ -127,6 +128,7 @@ function _subprocess:close()
-- close process
ok = process._close(self:cdata())
if ok then
+ process._openlist()[self:cdata()] = nil
self._PROC = nil
end
return ok
@@ -152,6 +154,16 @@ function _subprocess:__gc()
end
end
+-- get all opened processes list
+function process._openlist()
+ local list = process._LIST
+ if not list then
+ list = {}
+ process._LIST = list
+ end
+ return list
+end
+
-- open a subprocess
--
-- @param command the process command
@@ -239,5 +251,14 @@ function process.openv(shellname, argv, opt)
end
end
+-- kill all pending process
+function process.killall()
+ for _, proc in pairs(process._openlist()) do
+ if proc and proc:cdata() then
+ proc:kill()
+ end
+ end
+end
+
-- return module: process
return process