//go:build !windows
// +build !windows

package scheduler

import (
	"os/exec"
	"syscall"
)

// setProcessGroup sets up process group for clean termination on Unix systems
func setProcessGroup(cmd *exec.Cmd) {
	if cmd.SysProcAttr == nil {
		cmd.SysProcAttr = &syscall.SysProcAttr{}
	}
	cmd.SysProcAttr.Setpgid = true
}

// killProcessGroup kills the entire process group on Unix systems
func killProcessGroup(cmd *exec.Cmd) {
	if cmd != nil && cmd.Process != nil {
		// Negative PID kills the entire process group
		_ = syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL)
	}
}

// isProcessRunning checks if a process is still running on Unix systems
func isProcessRunning(cmd *exec.Cmd) bool {
	if cmd == nil || cmd.Process == nil {
		return false
	}
	// Signal 0 is a no-op that just checks if process exists
	return cmd.Process.Signal(syscall.Signal(0)) == nil
}
