On Tue, 21 Apr 2026 15:49:25 GMT, Roger Riggs <[email protected]> wrote:
> > I wouldn't say that is desired behavior. It's just what is observed but is > > platform specific and undocumented. I'm not sure special casing pid == 0 in > > the shared code is a good idea. What if the other platforms have similar > > behavior, but for different pid values? I think also checking before > > dereferencing an out of range index value is still prudent regardless. > > `getDescendents()` does not expect to find the requested pid in the result > stream/list. The use of zero in the call to native is intended to fetch info > for all processes. > > Hmm, I don't think process 0 is real and am surprised to find a process zero > with parent zero in the result list. I don't have a Linux handy to check. > `ps` on MacOS does not list it. `ps -p 0`. Process ids are OS specific so > there is no spec to throw IAE on `ProcessHandle.of(0)`. But I don't think pid > zero should be exposed. > > If a process zero is not real then the API should return an empty list for > calls to `ProcessHandle.of(0).getDescendents().toList()`. ProcessHandle.of(0) returns a real handle on Mac, but not on Linux or Windows. We could disallow its creation on Mac too, but existing code could be using it. The parent of `1` is `0` and the parent of `0` is itself. jshell> ProcessHandle.of(0).get().info() $1 ==> [user: Optional[root], startTime: Optional[2026-04-19T12:05:59.162Z]] ------------- PR Comment: https://git.openjdk.org/jdk/pull/30763#issuecomment-4290176581
