Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Commit

Permalink
Fix #438 When debug process is stopped kill all processes started by it(
Browse files Browse the repository at this point in the history
#765)

* Attempt to fix #438

* Fix linting issues
  • Loading branch information
roblourens authored and ramya-rao-a committed Feb 6, 2017
1 parent dc9b14f commit 40362d1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
12 changes: 12 additions & 0 deletions scripts/terminateProcess.sh
@@ -0,0 +1,12 @@
#!/bin/bash

terminateTree() {
for cpid in $(/usr/bin/pgrep -P $1); do
terminateTree $cpid
done
kill -9 $1 > /dev/null 2>&1
}

for pid in $*; do
terminateTree $pid
done
24 changes: 22 additions & 2 deletions src/debugAdapter/goDebug.ts
Expand Up @@ -9,7 +9,7 @@ import { DebugProtocol } from 'vscode-debugprotocol';
import { DebugSession, InitializedEvent, TerminatedEvent, ThreadEvent, StoppedEvent, OutputEvent, Thread, StackFrame, Scope, Source, Handles } from 'vscode-debugadapter';
import { readFileSync, existsSync, lstatSync } from 'fs';
import { basename, dirname } from 'path';
import { spawn, ChildProcess } from 'child_process';
import { spawn, ChildProcess, execSync, spawnSync } from 'child_process';
import { Client, RPCConnection } from 'json-rpc2';
import { getBinPathWithPreferredGopath } from '../goPath';
import * as logger from 'vscode-debug-logger';
Expand Down Expand Up @@ -307,7 +307,7 @@ class Delve {
});
});
} else {
this.debugProcess.kill();
killTree(this.debugProcess.pid);
}
}
}
Expand Down Expand Up @@ -759,4 +759,24 @@ function random(low: number, high: number): number {
return Math.floor(Math.random() * (high - low) + low);
}

function killTree(processId: number): void {
if (process.platform === 'win32') {
const TASK_KILL = 'C:\\Windows\\System32\\taskkill.exe';

// when killing a process in Windows its child processes are *not* killed but become root processes.
// Therefore we use TASKKILL.EXE
try {
execSync(`${TASK_KILL} /F /T /PID ${processId}`);
} catch (err) {
}
} else {
// on linux and OS X we kill all direct and indirect child processes as well
try {
const cmd = path.join(__dirname, '../../../scripts/terminateProcess.sh');
spawnSync(cmd, [ processId.toString() ]);
} catch (err) {
}
}
}

DebugSession.run(GoDebugSession);

0 comments on commit 40362d1

Please sign in to comment.