Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions localexec.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (

// LocalExecer executes command on the local system.
type LocalExecer struct {
// ChildProcessPriority overrides the default niceness of all child processes launch by LocalExecer.
ChildProcessPriority *int
}

func (l *localProcess) Stdin() io.WriteCloser {
Expand Down
9 changes: 9 additions & 0 deletions localexec_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ func (l LocalExecer) Start(ctx context.Context, c Command) (Process, error) {
if err != nil {
return nil, xerrors.Errorf("start command: %w", err)
}

if l.ChildProcessPriority != nil {
pid := process.cmd.Process.Pid
niceness := *l.ChildProcessPriority
err := syscall.Setpriority(syscall.PRIO_PROCESS, pid, niceness)
if err != nil {
return nil, xerrors.Errorf("set process (pid: %d) priority to (niceness: %d): %w", pid, niceness, err)
}
}
}

return &process, nil
Expand Down