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