//go:build windows

package proc

import (
	"errors"

	"golang.org/x/sys/windows"
)

// PIDAlive reports whether pid appears in the Windows process table without
// depending on localized tasklist output. Errors other than "no such PID" are
// treated as alive so callers continue to fail closed for protected processes.
func PIDAlive(pid int) bool {
	if pid <= 0 || uint64(pid) > uint64(^uint32(0)) {
		return false
	}
	handle, err := windows.OpenProcess(
		windows.PROCESS_QUERY_LIMITED_INFORMATION,
		false,
		uint32(pid),
	)
	if err == nil {
		windows.CloseHandle(handle)
		return true
	}
	return !errors.Is(err, windows.ERROR_INVALID_PARAMETER)
}
