No public description

PiperOrigin-RevId: 843835446
Change-Id: Id737de4a494dc79e9f2044f37caced6a5d2623da
diff --git a/src/main/java/com/google/devtools/build/lib/BUILD b/src/main/java/com/google/devtools/build/lib/BUILD
index 283099b..e98aa55 100644
--- a/src/main/java/com/google/devtools/build/lib/BUILD
+++ b/src/main/java/com/google/devtools/build/lib/BUILD
@@ -533,7 +533,6 @@
         "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/analysis:remote_analysis_caching_services_supplier",
         "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/analysis:remote_analysis_json_log_writer",
         "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/analysis:remote_analysis_metadata_writer",
-        "//src/main/java/com/google/devtools/build/lib/unix:process_utils_service",
         "//src/main/java/com/google/devtools/build/lib/unsafe:string",
         "//src/main/java/com/google/devtools/build/lib/util",
         "//src/main/java/com/google/devtools/build/lib/util:TestType",
@@ -551,6 +550,7 @@
         "//src/main/java/com/google/devtools/build/lib/util:memory_accountant",
         "//src/main/java/com/google/devtools/build/lib/util:object_graph_traverser",
         "//src/main/java/com/google/devtools/build/lib/util:os",
+        "//src/main/java/com/google/devtools/build/lib/util:process",
         "//src/main/java/com/google/devtools/build/lib/util:shallow_object_size_computer",
         "//src/main/java/com/google/devtools/build/lib/util:string",
         "//src/main/java/com/google/devtools/build/lib/util:string_encoding",
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/BUILD b/src/main/java/com/google/devtools/build/lib/bazel/BUILD
index 0804711..5fe31ef 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/BUILD
+++ b/src/main/java/com/google/devtools/build/lib/bazel/BUILD
@@ -201,7 +201,6 @@
         "//src/main/java/com/google/devtools/build/lib/skyframe/serialization:serialization_module",
         "//src/main/java/com/google/devtools/build/lib/standalone",
         "//src/main/java/com/google/devtools/build/lib/starlarkdebug/module",
-        "//src/main/java/com/google/devtools/build/lib/unix:process_utils_service_impl",
         "//src/main/java/com/google/devtools/build/lib/worker:worker_module",
         "//third_party:guava",
     ],
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/Bazel.java b/src/main/java/com/google/devtools/build/lib/bazel/Bazel.java
index 824ad46..aa4987c 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/Bazel.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/Bazel.java
@@ -108,8 +108,7 @@
           new com.google.devtools.build.lib.skyframe.FsEventsNativeDepsServiceImpl(),
           new com.google.devtools.build.lib.platform.PlatformNativeDepsServiceImpl(),
           new com.google.devtools.build.lib.profiler.SystemNetworkStatsServiceImpl(),
-          new com.google.devtools.build.lib.profiler.TraceProfilerServiceImpl(),
-          new com.google.devtools.build.lib.unix.ProcessUtilsServiceImpl());
+          new com.google.devtools.build.lib.profiler.TraceProfilerServiceImpl());
 
   public static void main(String[] args) {
     BlazeVersionInfo.setBuildInfo(tryGetBuildInfo());
diff --git a/src/main/java/com/google/devtools/build/lib/sandbox/BUILD b/src/main/java/com/google/devtools/build/lib/sandbox/BUILD
index 9f21d66..850beb2 100644
--- a/src/main/java/com/google/devtools/build/lib/sandbox/BUILD
+++ b/src/main/java/com/google/devtools/build/lib/sandbox/BUILD
@@ -339,8 +339,8 @@
         "//src/main/java/com/google/devtools/build/lib/exec/local",
         "//src/main/java/com/google/devtools/build/lib/remote/options",
         "//src/main/java/com/google/devtools/build/lib/shell",
-        "//src/main/java/com/google/devtools/build/lib/unix:process_utils_service",
         "//src/main/java/com/google/devtools/build/lib/util:os",
+        "//src/main/java/com/google/devtools/build/lib/util:process",
         "//src/main/java/com/google/devtools/build/lib/vfs",
         "//src/main/java/com/google/devtools/build/lib/vfs:pathfragment",
         "//src/main/protobuf:failure_details_java_proto",
diff --git a/src/main/java/com/google/devtools/build/lib/sandbox/DockerSandboxedSpawnRunner.java b/src/main/java/com/google/devtools/build/lib/sandbox/DockerSandboxedSpawnRunner.java
index 3847f6b..85b4cdb 100644
--- a/src/main/java/com/google/devtools/build/lib/sandbox/DockerSandboxedSpawnRunner.java
+++ b/src/main/java/com/google/devtools/build/lib/sandbox/DockerSandboxedSpawnRunner.java
@@ -40,8 +40,8 @@
 import com.google.devtools.build.lib.server.FailureDetails.Sandbox.Code;
 import com.google.devtools.build.lib.shell.Command;
 import com.google.devtools.build.lib.shell.CommandException;
-import com.google.devtools.build.lib.unix.ProcessUtilsService;
 import com.google.devtools.build.lib.util.OS;
+import com.google.devtools.build.lib.util.ProcessUtils;
 import com.google.devtools.build.lib.vfs.Path;
 import com.google.devtools.build.lib.vfs.PathFragment;
 import java.io.ByteArrayInputStream;
@@ -93,18 +93,17 @@
     // create files as 'root' and we can't move them to the execRoot.
     if (OS.getCurrent() == OS.LINUX) {
       try {
-        var unused = ProcessUtilsService.getService().getuid();
-        unused = ProcessUtilsService.getService().getgid();
+        ProcessUtils.getuid();
+        ProcessUtils.getgid();
       } catch (UnsatisfiedLinkError e) {
         if (verbose) {
           cmdEnv
               .getReporter()
               .handle(
                   Event.error(
-                      "Docker sandboxing is disabled, because"
-                          + " ProcessUtilsService.getService().getuid/getgid threw an"
-                          + " UnsatisfiedLinkError. This means that you're running a Bazel version"
-                          + " that doesn't have JNI libraries - did you build it correctly?\n"
+                      "Docker sandboxing is disabled, because ProcessUtils.getuid/getgid threw an "
+                          + "UnsatisfiedLinkError. This means that you're running a Bazel version "
+                          + "that doesn't have JNI libraries - did you build it correctly?\n"
                           + Throwables.getStackTraceAsString(e)));
         }
         return false;
@@ -187,8 +186,8 @@
     this.treeDeleter = treeDeleter;
     this.cmdEnv = cmdEnv;
     if (OS.getCurrent() == OS.LINUX) {
-      this.uid = ProcessUtilsService.getService().getuid();
-      this.gid = ProcessUtilsService.getService().getgid();
+      this.uid = ProcessUtils.getuid();
+      this.gid = ProcessUtils.getgid();
     } else {
       this.uid = -1;
       this.gid = -1;
diff --git a/src/main/java/com/google/devtools/build/lib/unix/BUILD b/src/main/java/com/google/devtools/build/lib/unix/BUILD
index c36ecd2..bac7e1f 100644
--- a/src/main/java/com/google/devtools/build/lib/unix/BUILD
+++ b/src/main/java/com/google/devtools/build/lib/unix/BUILD
@@ -5,11 +5,6 @@
     default_visibility = ["//src:__subpackages__"],
 )
 
-PROCESS_UTILS_SRCS = [
-    "ProcessUtilsService.java",
-    "ProcessUtilsServiceImpl.java",
-]
-
 filegroup(
     name = "srcs",
     srcs = glob(["*"]),
@@ -20,7 +15,7 @@
     name = "unix",
     srcs = glob(
         ["*.java"],
-        exclude = PROCESS_UTILS_SRCS + ["ProcMeminfoParser.java"],
+        exclude = ["ProcMeminfoParser.java"],
     ),
     deps = [
         "//src/main/java/com/google/devtools/build/lib/bugreport",
@@ -42,21 +37,3 @@
     srcs = ["ProcMeminfoParser.java"],
     deps = ["//third_party:guava"],
 )
-
-java_library(
-    name = "process_utils_service",
-    srcs = ["ProcessUtilsService.java"],
-    deps = [
-        "//src/main/java/com/google/devtools/build/lib:runtime/blaze_service",
-    ],
-)
-
-java_library(
-    name = "process_utils_service_impl",
-    srcs = ["ProcessUtilsServiceImpl.java"],
-    deps = [
-        ":process_utils_service",
-        "//src/main/java/com/google/devtools/build/lib/jni",
-        "//src/main/java/com/google/devtools/build/lib/util:os",
-    ],
-)
diff --git a/src/main/java/com/google/devtools/build/lib/unix/ProcessUtils.java b/src/main/java/com/google/devtools/build/lib/unix/ProcessUtils.java
new file mode 100644
index 0000000..ef0f39a
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/unix/ProcessUtils.java
@@ -0,0 +1,42 @@
+// Copyright 2014 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//    http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package com.google.devtools.build.lib.unix;
+
+import com.google.devtools.build.lib.jni.JniLoader;
+
+/**
+ * Various utilities related to UNIX processes.
+ */
+public final class ProcessUtils {
+
+  static {
+    JniLoader.loadJni();
+  }
+
+  private ProcessUtils() {}
+
+  /**
+   * Native wrapper around POSIX getgid(2).
+   *
+   * @return the real group ID of the current process.
+   */
+  public static native int getgid();
+
+  /**
+   * Native wrapper around POSIX getuid(2).
+   *
+   * @return the real user ID of the current process.
+   */
+  public static native int getuid();
+}
diff --git a/src/main/java/com/google/devtools/build/lib/unix/ProcessUtilsService.java b/src/main/java/com/google/devtools/build/lib/unix/ProcessUtilsService.java
deleted file mode 100644
index 9e8d7c2..0000000
--- a/src/main/java/com/google/devtools/build/lib/unix/ProcessUtilsService.java
+++ /dev/null
@@ -1,47 +0,0 @@
-// Copyright 2025 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//    http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.google.devtools.build.lib.unix;
-
-import com.google.devtools.build.lib.runtime.BlazeService;
-import java.util.concurrent.atomic.AtomicReference;
-
-/** Service for various UNIX process utilities. */
-public interface ProcessUtilsService extends BlazeService {
-  static final AtomicReference<ProcessUtilsService> service = new AtomicReference<>();
-
-  public static void registerJniService(ProcessUtilsService service) {
-    ProcessUtilsService.service.set(service);
-  }
-
-  public static ProcessUtilsService getService() {
-    return service.get();
-  }
-
-  /**
-   * Returns the real group ID of the current process.
-   *
-   * @throws UnsatisfiedLinkError when JNI is not available.
-   * @throws UnsupportedOperationException on operating systems where this call is not implemented.
-   */
-  int getgid();
-
-  /**
-   * Returns the real user ID of the current process.
-   *
-   * @throws UnsatisfiedLinkError when JNI is not available.
-   * @throws UnsupportedOperationException on operating systems where this call is not implemented.
-   */
-  int getuid();
-}
diff --git a/src/main/java/com/google/devtools/build/lib/unix/ProcessUtilsServiceImpl.java b/src/main/java/com/google/devtools/build/lib/unix/ProcessUtilsServiceImpl.java
deleted file mode 100644
index 9d016c5..0000000
--- a/src/main/java/com/google/devtools/build/lib/unix/ProcessUtilsServiceImpl.java
+++ /dev/null
@@ -1,62 +0,0 @@
-// Copyright 2025 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//    http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-package com.google.devtools.build.lib.unix;
-
-import com.google.devtools.build.lib.jni.JniLoader;
-import com.google.devtools.build.lib.util.OS;
-
-/** Various utilities related to UNIX processes. */
-public final class ProcessUtilsServiceImpl implements ProcessUtilsService {
-
-  @Override
-  public void globalInit() {
-    ProcessUtilsService.registerJniService(this);
-  }
-
-  static {
-    JniLoader.loadJni();
-  }
-
-  public ProcessUtilsServiceImpl() {}
-
-  @Override
-  public int getgid() {
-    if (OS.getCurrent() == OS.WINDOWS) {
-      throw new UnsupportedOperationException();
-    }
-    return getgidNative();
-  }
-
-  @Override
-  public int getuid() {
-    if (OS.getCurrent() == OS.WINDOWS) {
-      throw new UnsupportedOperationException();
-    }
-    return getuidNative();
-  }
-
-  /**
-   * Native wrapper around POSIX getgid(2).
-   *
-   * @return the real group ID of the current process.
-   */
-  private native int getgidNative();
-
-  /**
-   * Native wrapper around POSIX getuid(2).
-   *
-   * @return the real user ID of the current process.
-   */
-  private native int getuidNative();
-}
diff --git a/src/main/java/com/google/devtools/build/lib/util/BUILD b/src/main/java/com/google/devtools/build/lib/util/BUILD
index 6e3d74f..42c542c 100644
--- a/src/main/java/com/google/devtools/build/lib/util/BUILD
+++ b/src/main/java/com/google/devtools/build/lib/util/BUILD
@@ -62,6 +62,18 @@
 )
 
 java_library(
+    name = "process",
+    srcs = ["ProcessUtils.java"],
+    deps = [
+        ":os",
+        "//src/main/java/com/google/devtools/build/lib/concurrent",
+        "//src/main/java/com/google/devtools/build/lib/concurrent:thread_safety",
+        "//src/main/java/com/google/devtools/build/lib/unix",
+        "//src/main/java/com/google/devtools/build/lib/windows:processes",
+    ],
+)
+
+java_library(
     name = "single_line_formatter",
     srcs = ["SingleLineFormatter.java"],
     deps = [
diff --git a/src/main/java/com/google/devtools/build/lib/util/ProcessUtils.java b/src/main/java/com/google/devtools/build/lib/util/ProcessUtils.java
new file mode 100644
index 0000000..02a5ed6
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/util/ProcessUtils.java
@@ -0,0 +1,56 @@
+// Copyright 2014 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//    http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.devtools.build.lib.util;
+
+import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe;
+
+/**
+ * OS Process related utilities.
+ *
+ * <p>Use {@link ProcessHandle#current()} and {@link ProcessHandle#pid()} to get the PID of the
+ * current process.
+ */
+@ThreadSafe
+public final class ProcessUtils {
+  private ProcessUtils() {
+    // prevent construction.
+  }
+
+  /**
+   * @return the real group ID of the current process.
+   * @throws UnsatisfiedLinkError when JNI is not available.
+   * @throws UnsupportedOperationException on operating systems where this call is not implemented.
+   */
+  public static int getgid() {
+    if (OS.getCurrent() == OS.WINDOWS) {
+      throw new UnsupportedOperationException();
+    } else {
+      return com.google.devtools.build.lib.unix.ProcessUtils.getgid();
+    }
+  }
+
+  /**
+   * @return the real user ID of the current process.
+   * @throws UnsatisfiedLinkError when JNI is not available.
+   * @throws UnsupportedOperationException on operating systems where this call is not implemented.
+   */
+  public static int getuid() {
+    if (OS.getCurrent() == OS.WINDOWS) {
+      throw new UnsupportedOperationException();
+    } else {
+      return com.google.devtools.build.lib.unix.ProcessUtils.getuid();
+    }
+  }
+}
diff --git a/src/main/native/process.cc b/src/main/native/process.cc
index 4fe4bdb..0aa57eb 100644
--- a/src/main/native/process.cc
+++ b/src/main/native/process.cc
@@ -17,23 +17,21 @@
 #include <unistd.h>
 
 /*
- * Class:     com.google.devtools.build.lib.unix.ProcessUtilsServiceImpl
+ * Class:     com.google.devtools.build.lib.unix.ProcessUtils
  * Method:    getgid
  * Signature: ()I
  */
 extern "C" JNIEXPORT jint JNICALL
-Java_com_google_devtools_build_lib_unix_ProcessUtilsServiceImpl_getgidNative(
-    JNIEnv* env, jobject local_object) {
+Java_com_google_devtools_build_lib_unix_ProcessUtils_getgid(JNIEnv *env, jclass clazz) {
   return getgid();
 }
 
 /*
- * Class:     com.google.devtools.build.lib.unix.ProcessUtilsServiceImpl
+ * Class:     com.google.devtools.build.lib.unix.ProcessUtils
  * Method:    getuid
  * Signature: ()I
  */
 extern "C" JNIEXPORT jint JNICALL
-Java_com_google_devtools_build_lib_unix_ProcessUtilsServiceImpl_getuidNative(
-    JNIEnv* env, jobject local_object) {
+Java_com_google_devtools_build_lib_unix_ProcessUtils_getuid(JNIEnv *env, jclass clazz) {
   return getuid();
 }