From 7e27f3ff9559788ea78548a803c3433f8384e74f 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. (cherry picked from commit 3899b2d7783f6f40d3681dfbf152048d0dc05fa1) --- uci/engine.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/uci/engine.go b/uci/engine.go index 31344c5fd..f093f9f23 100644 --- a/uci/engine.go +++ b/uci/engine.go @@ -57,12 +57,19 @@ func New(path string, opts ...func(e *Engine)) (*Engine, error) { for _, opt := range opts { opt(e) } - go func() { - _ = 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