From 3899b2d7783f6f40d3681dfbf152048d0dc05fa1 Mon Sep 17 00:00:00 2001 From: Mike Brown Date: Fri, 4 Jun 2021 23:17:21 +0000 Subject: [PATCH] Add uci.Engine.Getpid() This change adds a Getpid() method receiver to uci.Engine. This enables callers to interact with the engine process directly. For example callers may renice the process to allow the engine to run at a lower priority. In practice this is helpful in improving system responsiveness when running the engine with high thread counts and/or larger hash sizes. --- uci/engine.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/uci/engine.go b/uci/engine.go index 2008059..1d8ad2e 100644 --- a/uci/engine.go +++ b/uci/engine.go @@ -55,10 +55,18 @@ func New(path string, opts ...func(e *Engine)) (*Engine, error) { for _, opt := range opts { opt(e) } - go e.cmd.Run() + err = e.cmd.Start() + if err != nil { + return nil, fmt.Errorf("uci: failed to start executable %s: %w", path, err) + } + go e.cmd.Wait() return e, nil } +func (e *Engine) Getpid() int { + return e.cmd.Process.Pid +} + // ID returns the id values returned from the most recent CmdUCI invocation. It includes // key value data such as the following: // id name Stockfish 12