mirror of
https://github.com/seriousm4x/UpSnap.git
synced 2026-03-31 06:24:09 -04:00
36 lines
775 B
Go
36 lines
775 B
Go
//go:build !windows
|
|
// +build !windows
|
|
|
|
package networking
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
|
|
"github.com/seriousm4x/upsnap/logger"
|
|
"golang.org/x/sys/unix"
|
|
)
|
|
|
|
// Set platform specifiy custom process attributes
|
|
func SetProcessAttributes(cmd *exec.Cmd) {
|
|
cmd.SysProcAttr = &unix.SysProcAttr{Setpgid: true}
|
|
}
|
|
|
|
// Kills child processes on Linux. Windows doesn't provide a direct way to kill child processes, so we kill just the main process.
|
|
func KillProcess(process *os.Process) error {
|
|
logger.Warning.Println("Your command didn't finish in time. It will be killed.")
|
|
pgid, err := unix.Getpgid(process.Pid)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = unix.Kill(-pgid, unix.SIGTERM)
|
|
if err != nil {
|
|
return unix.Kill(-pgid, unix.SIGKILL)
|
|
}
|
|
|
|
_, err = process.Wait()
|
|
|
|
return err
|
|
}
|