File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -339,14 +339,22 @@ fn get_processes(state: State<SysState>) -> Vec<ProcessInfo> {
339339 procs
340340}
341341
342- /// Kills a process by PID. Returns true on success .
342+ /// Kills a process by PID. Returns success or an error message .
343343#[ tauri:: command]
344- fn kill_process ( pid : u32 , state : State < SysState > ) -> bool {
345- let sys = state. sys . lock ( ) . unwrap ( ) ;
344+ fn kill_process ( pid : u32 , state : State < SysState > ) -> Result < ( ) , String > {
345+ let mut sys = state. sys . lock ( ) . unwrap ( ) ;
346+
347+ // Refresh only the processes to get an up-to-date PID list
348+ sys. refresh_processes ( sysinfo:: ProcessesToUpdate :: All , true ) ;
349+
346350 if let Some ( p) = sys. process ( sysinfo:: Pid :: from_u32 ( pid) ) {
347- p. kill ( )
351+ if p. kill ( ) {
352+ Ok ( ( ) )
353+ } else {
354+ Err ( "Failed to kill process (permission denied or system protected)" . to_string ( ) )
355+ }
348356 } else {
349- false
357+ Err ( format ! ( "Process with PID {} not found or already terminated" , pid ) )
350358 }
351359}
352360
You can’t perform that action at this time.
0 commit comments