MCPcopy Create free account
hub / github.com/bytecodealliance/rustix / get_reaper_pids

Function get_reaper_pids

src/process/procctl.rs:362–386  ·  view source on GitHub ↗
(process: ProcSelector)

Source from the content-addressed store, hash-verified

360#[cfg(feature = "alloc")]
361#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
362pub fn get_reaper_pids(process: ProcSelector) -> io::Result<Vec<PidInfo>> {
363 // Sadly no better way to guarantee that we get all the results than to
364 // allocate ≈8MB of memory…
365 const PID_MAX: usize = 99999;
366 let mut pids: Vec<procctl_reaper_pidinfo> = vec![Default::default(); PID_MAX];
367 let mut pinfo = procctl_reaper_pids {
368 rp_count: PID_MAX as _,
369 rp_pad0: [0; 15],
370 rp_pids: pids.as_mut_slice().as_mut_ptr(),
371 };
372 unsafe { procctl(PROC_REAP_GETPIDS, process, as_mut_ptr(&mut pinfo).cast())? };
373 let mut result = Vec::new();
374 for raw in pids.into_iter() {
375 let flags = PidInfoFlags::from_bits_retain(raw.pi_flags);
376 if !flags.contains(PidInfoFlags::VALID) {
377 break;
378 }
379 result.push(PidInfo {
380 flags,
381 subtree: Pid::from_raw(raw.pi_subtree).ok_or(io::Errno::RANGE)?,
382 pid: Pid::from_raw(raw.pi_pid).ok_or(io::Errno::RANGE)?,
383 });
384 }
385 Ok(result)
386}
387
388const PROC_REAP_KILL: c_int = 6;
389

Callers

nothing calls this directly

Calls 6

as_mut_ptrFunction · 0.85
containsMethod · 0.80
pushMethod · 0.80
procctlFunction · 0.70
as_mut_ptrMethod · 0.45
as_mut_sliceMethod · 0.45

Tested by

no test coverage detected