Documentation
¶
Overview ¶
Package gameproc finds, stops and waits for a game's processes, natively or under Wine, Proton, dotnet or mono, on Linux (including from inside a Flatpak) and Windows.
Index ¶
- Variables
- func Alive(pid int) bool
- func ImagePath(pid int) (string, error)
- func KillTree(pid int)
- func PrepareTree(cmd *exec.Cmd, _ bool)
- func StartOwnConsole([]string, string, string, []string) (<-chan error, error)
- func Stop(ctx context.Context, p Process, grace time.Duration) error
- func Terminate(pid int, grace time.Duration) error
- func TrackTree(pid int) error
- func UntrackTree(int)
- type Process
- type Status
Constants ¶
This section is empty.
Variables ¶
var ErrNoConsole = errors.New("gameproc: a program with its own console starts only on Windows")
ErrNoConsole is StartOwnConsole's error off Windows.
var ErrNotChild = errors.New("gameproc: the process is not a child, so its exit status is unknown")
ErrNotChild is WaitPID's error, joined with the wait error, for a Unix process that is not the caller's child: it was waited out, but its exit status is unknown.
var ErrNotTracked = errors.New("gameproc: the process runs outside a job")
ErrNotTracked is TrackTree's error, joined with its cause, for a process that was resumed but that no job holds: KillTree then ends only the process.
Functions ¶
func Alive ¶
Alive reports whether a process with this pid exists; a pid of 0 or less never does. In a Flatpak a failure to ask the host reads as false; callers that must tell the two apart (Stop, WaitPID) use hostProbe.
func ImagePath ¶
ImagePath is the executable of pid, read from /proc/<pid>/exe. It is an error where there is no /proc (macOS) and for a process the caller may not inspect. A deleted executable keeps the " (deleted)" suffix the kernel adds.
func KillTree ¶
func KillTree(pid int)
KillTree sends SIGTERM to the process group PrepareTree made pid the leader of. It refuses pid 1 and below, since kill(-1, ...) signals every process the user owns.
func PrepareTree ¶
PrepareTree puts the process in a group of its own, so KillTree can end it with everything it started. The noConsole argument has no effect off Windows. Any SysProcAttr the caller set is kept.
func StartOwnConsole ¶
StartOwnConsole starts a program in a new console that it reads and writes itself. That exists only on Windows; elsewhere it returns ErrNoConsole.
func Stop ¶
Stop is Terminate, after asking a Wine process to close its windows first, as quitting it would: a program that registered with a running launcher (Steam) signs off only on a clean exit, and killed instead it stays listed under its Wine pid, which the launcher then waits on for good. Whatever is still running after grace is terminated. The polite close is skipped inside a Flatpak, where the process's environment is not readable.
func Terminate ¶
Terminate asks the process to exit (SIGTERM) and kills it if it is still there after grace. A process that is already gone is success; one the caller may not signal is an error.
Types ¶
type Process ¶
Process is a running process. Args is nil where the platform gives no command line (Windows). Exe is empty where the platform will not say which file the process runs (another user's process, a host listing from a Flatpak). Start is the zero time when unknown.
func Processes ¶
Processes lists running processes whose program is one of names, in one pass over the process table. procDir is a /proc-shaped tree. Only the literal "/proc" inside a Flatpak lists the host's processes, through flatpak-spawn (which needs --talk-name=org.freedesktop.Flatpak); a fake tree is never sent to the host.
func (Process) ExeIs ¶
ExeIs reports whether p's executable is one of the programs names, so its path is where the game itself runs from; it is false for an unreadable executable and for a host (Wine, Proton, dotnet) that runs the game.
func (Process) LinkedFrom ¶
LinkedFrom reports whether p's executable is the target of the file of the same name in dir. A mod manager that deploys by symlink puts the loader in the game folder as a link into its staging folder, and Windows names a process by the link's target, so the process path alone would not place it in the install.
func (Process) RunsFrom ¶
RunsFrom reports whether p belongs to the install in dir: its executable is inside dir, or a command-line argument names a path inside it. Wine and Proton processes show the Windows path of the game, which sits under Z: for a file outside the prefix, so that form counts as the Unix path it maps to.
type Status ¶
Status is how a process ended. Signal is the Unix signal name ("SIGSEGV") of a process a signal killed, and is empty on Windows. A killed process has Code 128 plus the signal number.
func StatusOf ¶
StatusOf maps exec.Cmd.Wait's error to a Status. A process killed by a signal has Code 128 plus the signal number and the signal's name in Signal. An error that is not an exit is Code 1.
func WaitPID ¶
WaitPID waits until pid exits. The exit status is readable only for the caller's own child (os.FindProcess(pid).Wait()). For any other process it polls Alive until the exit and returns an empty Status and an error matching ErrNotChild, so a caller can tell an unknown exit from a clean one. Inside a Flatpak it returns a nil error once the host probe says the process is gone.