$OpenBSD: patch-base_process_process_posix_cc,v 1.17 2018/09/12 17:08:22 robert Exp $

Index: base/process/process_posix.cc
--- base/process/process_posix.cc.orig
+++ base/process/process_posix.cc
@@ -9,6 +9,7 @@
 #include <stdint.h>
 #include <sys/resource.h>
 #include <sys/wait.h>
+#include <signal.h>
 
 #include "base/debug/activity_tracker.h"
 #include "base/files/scoped_file.h"
@@ -24,6 +25,9 @@
 
 namespace {
 
+const int kBackgroundPriority = 5;
+const int kForegroundPriority = 0;
+
 #if !defined(OS_NACL_NONSFI)
 
 bool WaitpidWithTimeout(base::ProcessHandle handle,
@@ -262,12 +266,10 @@ Process Process::DeprecatedGetProcessFromHandle(Proces
   return Process(handle);
 }
 
-#if !defined(OS_LINUX) && !defined(OS_MACOSX) && !defined(OS_AIX)
 // static
 bool Process::CanBackgroundProcesses() {
-  return false;
+  return true;
 }
-#endif  // !defined(OS_LINUX) && !defined(OS_MACOSX) && !defined(OS_AIX)
 
 // static
 void Process::TerminateCurrentProcessImmediately(int exit_code) {
@@ -351,21 +353,23 @@ bool Process::WaitForExitWithTimeout(TimeDelta timeout
 
 void Process::Exited(int exit_code) const {}
 
-#if !defined(OS_LINUX) && !defined(OS_MACOSX) && !defined(OS_AIX)
 bool Process::IsProcessBackgrounded() const {
   // See SetProcessBackgrounded().
   DCHECK(IsValid());
-  return false;
+  return GetPriority() == kBackgroundPriority;
 }
 
-bool Process::SetProcessBackgrounded(bool value) {
-  // Not implemented for POSIX systems other than Linux and Mac. With POSIX, if
-  // we were to lower the process priority we wouldn't be able to raise it back
-  // to its initial priority.
-  NOTIMPLEMENTED();
-  return false;
+bool Process::SetProcessBackgrounded(bool background) {
+  DCHECK(IsValid());
+
+  if (!CanBackgroundProcesses())
+    return false;
+
+  int priority = background ? kBackgroundPriority : kForegroundPriority;
+  int result = setpriority(PRIO_PROCESS, process_, priority);
+  DPCHECK(result == 0);
+  return result == 0;
 }
-#endif  // !defined(OS_LINUX) && !defined(OS_MACOSX) && !defined(OS_AIX)
 
 int Process::GetPriority() const {
   DCHECK(IsValid());
