File tree Expand file tree Collapse file tree 3 files changed +36
-6
lines changed Expand file tree Collapse file tree 3 files changed +36
-6
lines changed Original file line number Diff line number Diff line change @@ -94,7 +94,11 @@ public:
94
94
95
95
void addMonitor (VMIdentifier monitor);
96
96
97
+ void addChildProcess (nativeint pid);
98
+
97
99
private:
100
+ void killChildProcesses ();
101
+
98
102
void notifyMonitors ();
99
103
100
104
void terminate ();
@@ -180,6 +184,10 @@ private:
180
184
nativeint _terminationStatus;
181
185
std::string _terminationReason;
182
186
187
+ // Spawned child processes to kill when terminating
188
+ private:
189
+ std::vector<nativeint> _childProcesses;
190
+
183
191
// Running thread management
184
192
private:
185
193
boost::asio::io_service::work* const _work;
Original file line number Diff line number Diff line change 28
28
#include < boost/bind.hpp>
29
29
#include < boost/random/random_device.hpp>
30
30
31
+ #ifdef MOZART_WINDOWS
32
+ # include < windows.h>
33
+ #else
34
+ # include < csignal>
35
+ #endif
36
+
31
37
namespace mozart { namespace boostenv {
32
38
33
39
// ///////////
@@ -280,6 +286,24 @@ void BoostVM::addMonitor(VMIdentifier monitor) {
280
286
_monitors.push_back (monitor);
281
287
}
282
288
289
+ void BoostVM::addChildProcess (nativeint pid) {
290
+ _childProcesses.push_back (pid);
291
+ }
292
+
293
+ void BoostVM::killChildProcesses () {
294
+ for (auto pid : _childProcesses) {
295
+ #ifndef MOZART_WINDOWS
296
+ kill (pid, SIGTERM);
297
+ #else
298
+ HANDLE hProcess = OpenProcess (PROCESS_TERMINATE, FALSE , pid);
299
+ if (hProcess) {
300
+ TerminateProcess (hProcess, 0 );
301
+ CloseHandle (hProcess);
302
+ }
303
+ #endif
304
+ }
305
+ }
306
+
283
307
void BoostVM::notifyMonitors () {
284
308
VMIdentifier deadVM = this ->identifier ;
285
309
std::string reason = this ->_terminationReason ;
@@ -300,6 +324,7 @@ void BoostVM::terminate() {
300
324
alarmTimer.cancel ();
301
325
302
326
portClosed = true ; // close VM port
327
+ killChildProcesses ();
303
328
notifyMonitors ();
304
329
305
330
env.removeTerminatedVM (identifier, _terminationStatus, _work);
Original file line number Diff line number Diff line change @@ -890,8 +890,7 @@ public:
890
890
vm->deleteStaticArray (argv, argc);
891
891
892
892
if (doKill) {
893
- // TODO
894
- // addChildProc(pid);
893
+ BoostVM::forVM (vm).addChildProcess (pid);
895
894
}
896
895
897
896
outPid = build (vm, pid);
@@ -1004,8 +1003,7 @@ public:
1004
1003
1005
1004
vm->deleteStaticArray(argv, argc);
1006
1005
1007
- // TODO
1008
- // addChildProc(pid);
1006
+ BoostVM::forVM(vm).addChildProcess(pid);
1009
1007
1010
1008
outPid = build(vm, pid);
1011
1009
outStatus = buildSharp(vm, rsock, wsock);
@@ -1092,8 +1090,7 @@ public:
1092
1090
1093
1091
vm->deleteStaticArray (argv, argc);
1094
1092
1095
- // TODO
1096
- // addChildProc(pid);
1093
+ BoostVM::forVM (vm).addChildProcess (pid);
1097
1094
1098
1095
outPid = build (vm, pid);
1099
1096
outStatus = std::move (ozPipe);
You can’t perform that action at this time.
0 commit comments