kill_process
Terminate a running process by providing its process ID (PID). Useful for stopping unresponsive or unwanted programs.
Instructions
Kill process
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| pid | Yes |
Implementation Reference
- src/tools/terminal_tools.js:387-447 (handler)The actual handler function `killProcess(pid)` that validates the PID, prevents killing critical system processes (0, 1, own PID), uses treeKill on Windows or SIGTERM/SIGKILL on POSIX, and returns success/error messages.
async function killProcess(pid) { try { // Validate PID if (!pid || isNaN(pid)) { return { success: false, message: 'Invalid PID provided' }; } // Don't allow killing critical system processes const criticalPids = [0, 1, process.pid]; if (criticalPids.includes(pid)) { return { success: false, message: 'Cannot kill critical system process' }; } if (process.platform === 'win32') { await new Promise((resolve, reject) => { treeKill(pid, undefined, (err) => (err ? reject(err) : resolve())); }); } else { // POSIX signals process.kill(pid, 'SIGTERM'); await new Promise(resolve => setTimeout(resolve, 100)); try { process.kill(pid, 0); // still running process.kill(pid, 'SIGKILL'); } catch (_) { // already exited } } return { success: true, message: `Process ${pid} terminated successfully`, pid }; } catch (error) { if (error.code === 'ESRCH') { return { success: false, message: `Process ${pid} not found` }; } else if (error.code === 'EPERM') { return { success: false, message: `Permission denied to kill process ${pid}` }; } logger.error(`Error killing process: ${error.message}`); return { success: false, message: error.message }; } } - src/mcp/server.js:102-102 (schema)Input schema registration for 'kill_process': defines the tool name, description ('Kill process'), and input schema requiring a numeric 'pid'.
{ name:'kill_process', description:'Kill process', inputSchema:{ type:'object', properties:{ pid:{type:'number'} }, required:['pid'] } }, - src/mcp/server.js:264-264 (registration)Dispatch/registration of the tool in the MCP server's request handler: routes 'kill_process' to `terminalTools.killProcess(args.pid)`.
case 'kill_process': data = await terminalTools.killProcess(args.pid); break; - src/tools/terminal_tools.js:2-2 (helper)Required dependency: `tree-kill` library imported for cross-platform process termination.
const treeKill = require('tree-kill'); - src/tools/terminal_tools.js:459-467 (registration)Module export of `killProcess` as part of the public API of terminal_tools.
module.exports = { getConfig, setConfigValue, executeCommand, readOutput, forceTerminate, listSessions, listProcesses, killProcess