Skip to main content

Mountain/IPC/WindServiceHandlers/NativeHost/
KillProcess.rs

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