Skip to main content

DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/IPC/WindServiceHandlers/NativeHost/
KillProcess.rs

1#![allow(non_snake_case)]
2
3//! `nativeHost:killProcess` - send SIGKILL (Unix) or TerminateProcess
4//! (Windows) to a child process. VS Code uses this to forcibly stop
5//! language servers and debug adapters that don't respond to graceful
6//! shutdown within their timeout.
7
8use serde_json::Value;
9
10use crate::dev_log;
11
12pub async fn KillProcess(Arguments:Vec<Value>) -> Result<Value, String> {
13	let Pid = Arguments.first().and_then(Value::as_u64).unwrap_or(0) as u32;
14
15	if Pid == 0 {
16		return Ok(Value::Null);
17	}
18
19	dev_log!("process", "nativeHost:killProcess pid={}", Pid);
20
21	#[cfg(unix)]
22	{
23		use std::process::Command;
24
25		let _ = Command::new("kill").args(["-9", &Pid.to_string()]).status();
26	}
27
28	#[cfg(windows)]
29	{
30		use std::process::Command;
31
32		let _ = Command::new("taskkill").args(["/F", "/PID", &Pid.to_string()]).status();
33	}
34
35	Ok(Value::Null)
36}