diff --git a/src/common.ts b/src/common.ts index b53909955..fbf5eda9c 100644 --- a/src/common.ts +++ b/src/common.ts @@ -5,6 +5,7 @@ import * as cp from 'child_process'; import * as fs from 'fs'; +import * as os from 'os'; import * as path from 'path'; let extensionPath: string; @@ -60,6 +61,41 @@ export function execChildProcess(command: string, workingDirectory: string = get }); } +export function getUnixChildProcessIds(pid: number): Promise { + return new Promise((resolve, reject) => { + let ps = cp.exec('ps -A -o ppid,pid', (error, stdout, stderr) => + { + if (error) { + return reject(error); + } + + if (stderr) { + return reject(stderr); + } + + if (!stdout) { + return resolve([]); + } + + let lines = stdout.split(os.EOL); + let pairs = lines.map(line => line.trim().split(/\s+/)); + + let children = []; + + for (let pair of pairs) { + let ppid = parseInt(pair[0]); + if (ppid === pid) { + children.push(parseInt(pair[1])); + } + } + + resolve(children); + }); + + ps.on('error', reject); + }); +} + export function fileExists(filePath: string): Promise { return new Promise((resolve, reject) => { fs.stat(filePath, (err, stats) => { diff --git a/src/omnisharp/server.ts b/src/omnisharp/server.ts index a9c4fc0ab..98c444737 100644 --- a/src/omnisharp/server.ts +++ b/src/omnisharp/server.ts @@ -16,6 +16,7 @@ import TelemetryReporter from 'vscode-extension-telemetry'; import * as os from 'os'; import * as path from 'path'; import * as protocol from './protocol'; +import * as utils from '../common'; import * as vscode from 'vscode'; enum ServerState { @@ -337,9 +338,15 @@ export class OmniSharpServer { }); } else { - // Kill Unix process - this._serverProcess.kill('SIGTERM'); - cleanupPromise = Promise.resolve(); + // Kill Unix process and children + cleanupPromise = utils.getUnixChildProcessIds(this._serverProcess.pid) + .then(children => { + for (let child of children) { + process.kill(child, 'SIGTERM'); + } + + this._serverProcess.kill('SIGTERM'); + }); } return cleanupPromise.then(() => {