panel_unix.go 759 B

1234567891011121314151617181920212223242526
  1. //go:build linux
  2. package panel
  3. import (
  4. "os/exec"
  5. "syscall"
  6. )
  7. func setDetachedProcess(cmd *exec.Cmd) {
  8. cmd.SysProcAttr = &syscall.SysProcAttr{Setsid: true}
  9. }
  10. // processAlive reports whether pid is still a live process, via the standard
  11. // POSIX kill(pid, 0) liveness check: it sends no actual signal, only checking
  12. // whether the target exists and is signalable. ESRCH means the process is
  13. // gone; any other result (including a permission error, which can only mean
  14. // the PID exists and belongs to someone) is treated as alive, since this is
  15. // used to decide whether it is safe to let a second update start.
  16. func processAlive(pid int) bool {
  17. if pid <= 0 {
  18. return false
  19. }
  20. err := syscall.Kill(pid, 0)
  21. return err == nil || err == syscall.EPERM
  22. }