物联网软件

This commit is contained in:
BBIT-Kai
2026-02-04 14:02:57 +08:00
parent 646e312a4c
commit 1c11f3f06c
28 changed files with 4526 additions and 271 deletions
+27
View File
@@ -6,6 +6,7 @@ package main
import (
"os"
"os/exec"
"strconv"
)
type mainProgramStarter struct{}
@@ -25,3 +26,29 @@ func (s *mainProgramStarter) Start(targetExe string) error {
// Linux 下:先保持最简单,保证能跑
return cmd.Start()
}
// 判断进程是否在运行
func (s *mainProgramStarter) IsProcessRunning(pid int) (bool, error) {
if pid <= 0 {
return false, nil
}
procPath := "/proc/" + strconv.Itoa(pid)
_, err := os.Stat(procPath)
if err == nil {
return true, nil
}
if os.IsNotExist(err) {
return false, nil
}
// 其他错误(例如权限问题)
return false, err
}
// 杀掉进程
func (l *mainProgramStarter) KillProcess(pid int) error {
cmd := exec.Command("kill", "-9", strconv.Itoa(pid))
return cmd.Run()
}