Files
tecamino-proccessSupervisor/htop/killHandler.go
Adrian Zürcher 9f262c4a55
All checks were successful
Build Process Supervisor / build (amd64, .exe, windows) (push) Successful in 2m24s
Build Process Supervisor / build (amd64, , linux) (push) Successful in 2m36s
Build Process Supervisor / build (arm, 6, , linux) (push) Successful in 2m19s
Build Process Supervisor / build (arm64, , linux) (push) Successful in 2m14s
more abstraction and simple dashboard for processes
2025-08-06 13:57:34 +02:00

41 lines
903 B
Go

package htop
import (
"html/template"
"net/http"
"os"
"processSupervisor/htop/models"
"strconv"
)
func KillHandler(w http.ResponseWriter, r *http.Request) {
pidStr := r.URL.Query().Get("pid")
pid, err := strconv.Atoi(pidStr)
if err != nil {
http.Error(w, "Invalid PID", http.StatusBadRequest)
return
}
proc, err := os.FindProcess(pid)
if err != nil {
http.Error(w, "Process not found", http.StatusNotFound)
return
}
err = proc.Kill()
if err != nil {
http.Error(w, "Failed to kill process", http.StatusInternalServerError)
return
}
// Return updated table partial (same as HTMX request)
processes, err := models.GetProcesses()
if err != nil {
http.Error(w, "Failed to get processes", http.StatusInternalServerError)
return
}
tmpl := template.Must(template.ParseFiles("templates/table.html"))
tmpl.Execute(w, processes)
}