Skip to content

Commit

Permalink
Add uci.Engine.Getpid()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mikeb26 committed Nov 26, 2024
1 parent e70b770 commit 3899b2d
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion uci/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3899b2d

Please sign in to comment.