cmd/syncthing, lib/config, lib/osutil: Lower process priority (fixes #4628)

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4675
This commit is contained in:
Jakob Borg
2018-01-15 17:11:14 +00:00
committed by Audrius Butkevicius
parent 838c182b5b
commit c554ffccc9
7 changed files with 142 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
// Copyright (C) 2018 The Syncthing Authors.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.
// +build !windows,!linux
package osutil
import (
"syscall"
"github.com/pkg/errors"
)
// SetLowPriority lowers the process CPU scheduling priority, and possibly
// I/O priority depending on the platform and OS.
func SetLowPriority() error {
// Process zero is "self", niceness value 9 is something between 0
// (default) and 19 (worst priority).
err := syscall.Setpriority(syscall.PRIO_PROCESS, 0, 9)
return errors.Wrap(err, "set niceness") // wraps nil as nil
}