1#![deny(unsafe_code)]
64
65#[cfg(target_os = "macos")]
66mod darwin_user_temp;
67#[cfg(target_os = "macos")]
68pub use darwin_user_temp::darwin_user_temp_dir;
69
70#[cfg(windows)]
71mod profile;
72#[cfg(windows)]
73pub use profile::profile_dir;
74
75#[cfg(unix)]
76mod user_home;
77#[cfg(unix)]
78pub use user_home::{effective_uid, real_user_home_dir};
79
80#[cfg(unix)]
81pub mod admission_gate;
82pub mod boot_id;
83#[cfg(unix)]
84pub mod child_exit;
85pub mod child_spawn;
86#[cfg(target_os = "macos")]
87pub mod code_signature;
88pub mod config_keychain;
89mod durable_replace;
90#[cfg(any(unix, windows))]
91mod retained_file;
92#[cfg(feature = "test-support")]
93pub use durable_replace::durable_replace_with_rename_hook;
94pub use durable_replace::{durable_replace, DurableReplaceError};
95#[cfg(any(unix, windows))]
96pub use retained_file::{
97 open_directory_nofollow_all, open_regular_nofollow, open_regular_nofollow_all,
98 retained_file_identity, OpenRegularError, RetainedFileIdentity,
99};
100#[cfg(windows)]
101pub use retained_file::{retained_file_index, WindowsFileIndexIdentity};
102#[cfg(all(unix, feature = "test-support"))]
103pub mod fork_exec_test;
104pub mod host;
105pub mod launch_nonce;
106pub mod local_peer;
107pub mod named_pipe;
108pub mod privacy_identity;
109#[cfg(unix)]
110pub mod process_group;
111pub mod process_identity;
112pub mod registration_channel;
113pub mod script_pipe;
114pub mod socket_peer;
115#[cfg_attr(not(windows), path = "windows_acl_noop.rs")]
116pub mod windows_acl;
117#[cfg(unix)]
118pub use launch_nonce::LaunchNonceHandoff;
119pub use launch_nonce::{
120 launch_nonce, LaunchNonce, LaunchNonceError, LaunchNonceSource, LAUNCH_NONCE_ENV,
121 LAUNCH_NONCE_FD, LAUNCH_NONCE_FD_ENV, LAUNCH_NONCE_PIPE_ENV, LAUNCH_NONCE_PIPE_FALLBACK_ENV,
122};
123
124#[cfg(windows)]
125pub use launch_nonce::{LaunchNoncePipeDelivery, LaunchNoncePipeHandoff};
126
127pub use registration_channel::{
128 registration_refusal, supervised, take_registration_channel, RegistrationChannel,
129 RegistrationChannelError, RegistrationRefusal,
130};
131
132#[cfg(target_os = "linux")]
133mod linux;
134#[cfg(target_os = "macos")]
135mod macos;
136
137#[cfg(target_os = "macos")]
138pub use macos::owned_child_start_time;
139#[cfg(windows)]
140mod windows;
141#[cfg(all(test, windows))]
142mod windows_tests;
143#[cfg(windows)]
144pub use windows::{
145 ExecutableCapture, ImageAgreement, ImageUnavailable, SpawnedImage, WindowsFileIdentity,
146};
147
148#[cfg(target_os = "linux")]
149use linux as platform;
150#[cfg(target_os = "macos")]
151use macos as platform;
152
153use std::{io, path::Path};
154
155pub const PROCESS_IDENTITY_SUPPORTED: bool =
157 cfg!(any(target_os = "linux", target_os = "macos", windows));
158
159#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
162pub struct FileIdentity {
163 pub device: u64,
164 pub inode: u64,
165}
166
167pub fn file_identity(path: &Path) -> Option<FileIdentity> {
170 #[cfg(unix)]
171 {
172 use std::os::unix::fs::MetadataExt;
173
174 std::fs::metadata(path).ok().map(|metadata| FileIdentity {
175 device: metadata.dev(),
176 inode: metadata.ino(),
177 })
178 }
179 #[cfg(not(unix))]
180 {
181 let _ = path;
182 None
183 }
184}
185
186#[derive(Debug, Clone, Copy, PartialEq, Eq)]
188pub struct Observation {
189 pub start_time: u64,
194 pub executable: Option<FileIdentity>,
199}
200
201#[derive(Debug, Clone, Copy, PartialEq, Eq)]
205pub enum ExecutableAccess {
206 Readable,
207 PermissionDenied,
208 Unavailable,
209}
210
211#[derive(Debug, Clone, Copy, PartialEq, Eq)]
213pub enum Signal {
214 Terminate,
216 Kill,
218}
219
220pub fn start_time(pid: u32) -> Option<u64> {
224 #[cfg(any(target_os = "linux", target_os = "macos"))]
225 {
226 platform::start_time(pid)
227 }
228 #[cfg(windows)]
229 {
230 Process::open(pid)
231 .ok()??
232 .observe()
233 .map(|observation| observation.start_time)
234 }
235 #[cfg(not(any(target_os = "linux", target_os = "macos", windows)))]
236 {
237 let _ = pid;
238 None
239 }
240}
241
242#[derive(Clone, Copy, Debug, PartialEq, Eq)]
244pub(crate) enum IdentityRead {
245 Alive(u64),
246 #[cfg_attr(windows, allow(dead_code))]
247 Gone,
249 Unknown,
250}
251
252#[cfg(all(test, any(target_os = "linux", target_os = "macos")))]
253mod identity_read_tests {
254 use super::*;
255
256 #[test]
257 fn identity_probe_distinguishes_alive_gone_and_invalid() {
258 let mut child = std::process::Command::new("/bin/sh")
259 .args(["-c", "exit 0"])
260 .spawn()
261 .unwrap();
262 let pid = child.id();
263 let until = std::time::Instant::now() + std::time::Duration::from_secs(5);
264 while read_identity(pid) != IdentityRead::Gone {
265 assert!(
266 std::time::Instant::now() < until,
267 "an exited owned child must become gone before reaping"
268 );
269 std::thread::yield_now();
270 }
271 child.wait().unwrap();
272 assert_eq!(
273 read_identity(pid),
274 IdentityRead::Gone,
275 "a missing owned PID is gone"
276 );
277 assert_eq!(read_identity(0), IdentityRead::Unknown);
278 assert!(matches!(
279 read_identity(std::process::id()),
280 IdentityRead::Alive(_)
281 ));
282 }
283}
284
285#[cfg(not(windows))]
286fn read_identity(pid: u32) -> IdentityRead {
287 #[cfg(any(target_os = "linux", target_os = "macos"))]
288 {
289 platform::read_identity(pid)
290 }
291 #[cfg(not(any(target_os = "linux", target_os = "macos")))]
292 {
293 start_time(pid).map_or(IdentityRead::Unknown, IdentityRead::Alive)
294 }
295}
296
297mod process_tree;
298pub use process_tree::{ProcessGroup, ProcessMember, ProcessTable, TreeUsage};
299
300pub fn process_start_time_ms(pid: u32) -> Option<u64> {
308 start_time_ms_from_native(start_time(pid)?)
309}
310
311fn start_time_ms_from_native(raw: u64) -> Option<u64> {
312 #[cfg(target_os = "linux")]
313 {
314 linux_start_time_ms(raw, || std::fs::read_to_string("/proc/stat").ok())
315 }
316 #[cfg(target_os = "macos")]
317 {
318 Some(raw / 1_000)
319 }
320 #[cfg(windows)]
321 {
322 (raw / 10_000).checked_sub(11_644_473_600_000)
323 }
324 #[cfg(not(any(target_os = "linux", target_os = "macos", windows)))]
325 {
326 let _ = raw;
327 None
328 }
329}
330
331#[cfg(target_os = "linux")]
332fn linux_start_time_ms(raw: u64, read_boot: impl FnOnce() -> Option<String>) -> Option<u64> {
333 let boot = read_boot()?
337 .lines()
338 .find_map(|line| line.strip_prefix("btime ")?.parse::<u64>().ok())?;
339 boot.checked_mul(1_000)?
340 .checked_add(raw.checked_mul(1_000)? / rustix::param::clock_ticks_per_second().max(1))
341}
342
343#[cfg(all(test, target_os = "linux"))]
344#[test]
345fn linux_start_identity_uses_fresh_boot_time_after_clock_step() {
346 let before = linux_start_time_ms(100, || Some("btime 1000\n".into())).unwrap();
347 let after = linux_start_time_ms(100, || Some("btime 1002\n".into())).unwrap();
348 assert_eq!(after - before, 2_000);
349}
350
351pub fn process_start_time_precision_ms() -> u64 {
353 #[cfg(target_os = "linux")]
354 {
355 1_000_u64.div_ceil(rustix::param::clock_ticks_per_second().max(1))
356 }
357 #[cfg(not(target_os = "linux"))]
358 {
359 1
360 }
361}
362
363pub fn parent_pid(pid: u32) -> Option<u32> {
366 #[cfg(any(target_os = "linux", target_os = "macos"))]
367 {
368 platform::parent_pid(pid)
369 }
370 #[cfg(windows)]
371 {
372 windows::parent_pid(pid)
373 }
374 #[cfg(not(any(target_os = "linux", target_os = "macos", windows)))]
375 {
376 let _ = pid;
377 None
378 }
379}
380
381pub const RESOURCE_USAGE_SUPPORTED: bool =
385 cfg!(any(target_os = "linux", target_os = "macos", windows));
386
387#[derive(Debug, Clone, Copy, PartialEq, Eq)]
390pub enum MemoryKind {
391 PhysFootprint,
395 ResidentSet,
399 WindowsWorkingSet,
402}
403
404#[derive(Debug, Clone, Copy, PartialEq, Eq)]
409pub struct ResourceUsage {
410 pub memory_bytes: u64,
412 pub memory_kind: MemoryKind,
413 pub swap_bytes: Option<u64>,
416 pub cpu_user: std::time::Duration,
418 pub cpu_system: std::time::Duration,
420}
421
422pub fn resource_usage(pid: u32) -> Option<ResourceUsage> {
434 #[cfg(any(target_os = "linux", target_os = "macos"))]
435 {
436 platform::resource_usage(pid)
437 }
438 #[cfg(windows)]
439 {
440 Process::open(pid).ok()??.resource_usage()
441 }
442 #[cfg(not(any(target_os = "linux", target_os = "macos", windows)))]
443 {
444 let _ = pid;
445 None
446 }
447}
448
449#[derive(Debug)]
451pub struct Process {
452 pid: u32,
453 #[cfg(target_os = "linux")]
454 pidfd: Option<std::os::fd::OwnedFd>,
455 #[cfg(windows)]
456 handle: std::os::windows::io::OwnedHandle,
457}
458
459impl Process {
460 pub fn open(pid: u32) -> io::Result<Option<Self>> {
470 #[cfg(target_os = "linux")]
471 {
472 linux::open(pid).map(|opened| opened.map(|pidfd| Self { pid, pidfd }))
473 }
474 #[cfg(target_os = "macos")]
475 {
476 Ok(platform::exists(pid).then_some(Self { pid }))
477 }
478 #[cfg(windows)]
479 {
480 windows::open(pid).map(|opened| opened.map(|handle| Self { pid, handle }))
481 }
482 #[cfg(not(any(target_os = "linux", target_os = "macos", windows)))]
483 {
484 let _ = pid;
485 Err(io::Error::new(
486 io::ErrorKind::Unsupported,
487 "process identity is not available on this platform",
488 ))
489 }
490 }
491
492 pub fn pid(&self) -> u32 {
493 self.pid
494 }
495
496 pub fn signals_through_pidfd(&self) -> bool {
499 #[cfg(target_os = "linux")]
500 {
501 self.pidfd.is_some()
502 }
503 #[cfg(not(target_os = "linux"))]
504 {
505 false
506 }
507 }
508
509 pub fn observe(&self) -> Option<Observation> {
513 self.observe_with_executable_access()
514 .map(|(observed, _)| observed)
515 }
516
517 pub fn is_alive_but_unobservable(&self) -> bool {
521 #[cfg(target_os = "linux")]
522 {
523 linux::alive_but_unobservable(self.pid, self.pidfd.as_ref())
524 }
525 #[cfg(not(target_os = "linux"))]
526 {
527 false
528 }
529 }
530
531 pub fn observe_with_executable_access(&self) -> Option<(Observation, ExecutableAccess)> {
535 #[cfg(any(target_os = "linux", target_os = "macos"))]
536 {
537 #[cfg(target_os = "linux")]
538 if !linux::pidfd_alive(self.pidfd.as_ref()) {
539 return None;
540 }
541 let start_time = platform::start_time(self.pid)?;
542 #[cfg(target_os = "linux")]
543 let (executable, access) = match linux::executable_identity(self.pid) {
544 Ok(identity) => (Some(identity), ExecutableAccess::Readable),
545 Err(error) if error.kind() == io::ErrorKind::PermissionDenied => {
546 (None, ExecutableAccess::PermissionDenied)
547 }
548 Err(_) => (None, ExecutableAccess::Unavailable),
549 };
550 #[cfg(target_os = "macos")]
551 let executable = macos::executable_identity(self.pid);
552 #[cfg(target_os = "macos")]
553 let access = if executable.is_some() {
554 ExecutableAccess::Readable
555 } else {
556 ExecutableAccess::Unavailable
557 };
558 Some((
559 Observation {
560 start_time,
561 executable,
562 },
563 access,
564 ))
565 }
566 #[cfg(windows)]
567 {
568 windows::observe(self).map(|observed| (observed, ExecutableAccess::Unavailable))
569 }
570 #[cfg(not(any(target_os = "linux", target_os = "macos", windows)))]
571 {
572 None
573 }
574 }
575
576 #[cfg(windows)]
579 pub fn wait_for_exit(&self, timeout: std::time::Duration) -> io::Result<bool> {
580 windows::wait(self, timeout)
581 }
582
583 #[cfg(windows)]
587 pub fn force_stop(
588 &self,
589 expected_start_time: u64,
590 timeout: std::time::Duration,
591 ) -> io::Result<bool> {
592 windows::force_stop(self, expected_start_time, timeout)
593 }
594
595 #[cfg(windows)]
600 pub fn terminate_with_exit_code(&self, exit_code: u32) -> io::Result<bool> {
601 windows::terminate_with_exit_code(self, exit_code)
602 }
603
604 #[cfg(windows)]
606 pub fn resource_usage(&self) -> Option<ResourceUsage> {
607 windows::resource_usage(self)
608 }
609
610 #[cfg(windows)]
613 pub fn cumulative_cpu_ms(&self) -> Option<u64> {
614 windows::cumulative_cpu_ms(self)
615 }
616
617 pub fn signal(&self, signal: Signal) -> io::Result<bool> {
631 #[cfg(any(target_os = "linux", target_os = "macos"))]
632 {
633 #[cfg(target_os = "linux")]
634 let result = linux::signal(self.pid, self.pidfd.as_ref(), signal);
635 #[cfg(target_os = "macos")]
636 let result = macos::signal(self.pid, signal);
637 match result {
638 Ok(()) => Ok(true),
639 Err(rustix::io::Errno::SRCH) => Ok(false),
640 Err(error) => Err(error.into()),
641 }
642 }
643 #[cfg(not(any(target_os = "linux", target_os = "macos")))]
644 {
645 let _ = signal;
646 Err(io::Error::new(
647 io::ErrorKind::Unsupported,
648 "process signalling is not available on this platform",
649 ))
650 }
651 }
652}
653
654#[cfg(all(test, any(target_os = "linux", target_os = "macos")))]
655mod tests {
656 use std::{
657 io::Read,
658 process::{Child, Command, Stdio},
659 time::{Duration, Instant},
660 };
661
662 use super::*;
663
664 fn spawn_sleep() -> Child {
665 Command::new("sleep")
666 .arg("60")
667 .spawn()
668 .expect("spawn sleep")
669 }
670
671 fn sleep_identity() -> FileIdentity {
673 let path = ["/bin/sleep", "/usr/bin/sleep"]
674 .into_iter()
675 .find(|path| Path::new(path).exists())
676 .expect("sleep is installed");
677 file_identity(Path::new(path)).expect("stat sleep")
678 }
679
680 fn wait_for_executable(process: &Process, expected: FileIdentity) -> Observation {
683 let deadline = Instant::now() + Duration::from_secs(5);
684 loop {
685 let observation = process.observe().expect("child is alive");
686 if observation.executable == Some(expected) || Instant::now() > deadline {
687 return observation;
688 }
689 std::thread::sleep(Duration::from_millis(10));
690 }
691 }
692
693 #[test]
694 fn own_process_is_observable_with_its_own_image() {
695 let process = Process::open(std::process::id())
696 .expect("open own process")
697 .expect("own process exists");
698 let observation = process.observe().expect("own process is alive");
699 let own_image = file_identity(&std::env::current_exe().unwrap()).unwrap();
700 assert_eq!(observation.executable, Some(own_image));
701 assert_eq!(start_time(std::process::id()), Some(observation.start_time));
702 }
703
704 #[test]
705 fn child_start_time_is_stable_and_differs_from_ours() {
706 let mut child = spawn_sleep();
707 let pid = child.id();
708 let process = Process::open(pid).unwrap().unwrap();
709 let observation = wait_for_executable(&process, sleep_identity());
710 assert_eq!(observation.executable, Some(sleep_identity()));
711 assert_eq!(start_time(pid), Some(observation.start_time));
712 child.kill().unwrap();
713 child.wait().unwrap();
714 }
715
716 #[test]
717 fn a_signalled_and_unreaped_child_reads_as_exited() {
718 let mut child = spawn_sleep();
719 let process = Process::open(child.id()).unwrap().unwrap();
720 assert!(process.signal(Signal::Terminate).unwrap());
721 let deadline = Instant::now() + Duration::from_secs(5);
722 while process.observe().is_some() {
723 assert!(Instant::now() < deadline, "child still observed as alive");
724 std::thread::sleep(Duration::from_millis(10));
725 }
726 assert_eq!(start_time(child.id()), None);
728 child.wait().unwrap();
729 }
730
731 #[test]
732 fn a_reaped_child_cannot_be_opened_or_observed() {
733 let mut child = spawn_sleep();
734 let pid = child.id();
735 child.kill().unwrap();
736 child.wait().unwrap();
737 if let Some(process) = Process::open(pid).unwrap() {
739 if let Some(observation) = process.observe() {
740 assert_ne!(observation.executable, Some(sleep_identity()));
741 }
742 }
743 }
744
745 #[cfg(target_os = "macos")]
749 #[test]
750 fn macos_start_time_is_microseconds_since_the_epoch() {
751 let now = std::time::SystemTime::now()
752 .duration_since(std::time::UNIX_EPOCH)
753 .unwrap()
754 .as_micros() as u64;
755 let started = start_time(std::process::id()).unwrap();
756 assert!(started <= now, "start time {started} is after now {now}");
757 assert!(
758 now - started < 3_600 * 1_000_000,
759 "start time {started} is more than an hour before now {now}"
760 );
761 }
762
763 fn thread_cpu_time() -> Duration {
767 let now = rustix::time::clock_gettime(rustix::time::ClockId::ThreadCPUTime);
768 Duration::new(now.tv_sec as u64, now.tv_nsec as u32)
769 }
770
771 fn burn_cpu(cpu: Duration) {
777 let start = thread_cpu_time();
778 let give_up = Instant::now() + Duration::from_secs(60);
779 let mut value = 0u64;
780 while thread_cpu_time().saturating_sub(start) < cpu {
781 assert!(
782 Instant::now() < give_up,
783 "thread CPU clock stopped advancing"
784 );
785 for step in 0..10_000u64 {
786 value = std::hint::black_box(value.wrapping_mul(31).wrapping_add(step));
787 }
788 }
789 std::hint::black_box(value);
790 }
791
792 #[test]
793 fn own_resource_usage_is_present_and_plausible() {
794 let pages = vec![0xa5u8; 8 * 1024 * 1024];
799 std::hint::black_box(&pages);
800 let usage = resource_usage(std::process::id()).expect("own process is readable");
801 assert!(
802 usage.memory_bytes >= pages.len() as u64,
803 "memory {} bytes cannot account for {} touched private bytes",
804 usage.memory_bytes,
805 pages.len()
806 );
807 std::hint::black_box(&pages);
808 assert!(
809 usage.memory_bytes < 64 * 1024 * 1024 * 1024,
810 "memory {} bytes is implausibly large",
811 usage.memory_bytes
812 );
813 #[cfg(target_os = "macos")]
814 assert_eq!(usage.memory_kind, MemoryKind::PhysFootprint);
815 #[cfg(target_os = "linux")]
816 {
817 assert_eq!(usage.memory_kind, MemoryKind::ResidentSet);
818 assert!(usage.swap_bytes.is_some(), "Linux reports VmSwap");
819 }
820 }
821
822 #[test]
827 fn own_cpu_time_grows_by_about_the_busy_work_done() {
828 let pid = std::process::id();
829 let total = |usage: ResourceUsage| usage.cpu_user + usage.cpu_system;
830 let before = total(resource_usage(pid).unwrap());
831 let busy = Duration::from_millis(400);
832 burn_cpu(busy);
833 let after = total(resource_usage(pid).unwrap());
834 let grown = after.saturating_sub(before);
835 assert!(
840 grown >= busy * 9 / 10,
841 "cpu time grew by {grown:?} over {busy:?} of busy work"
842 );
843 }
844
845 #[test]
846 fn a_child_reads_its_own_usage_not_ours() {
847 struct ChildGuard(Child);
848 impl Drop for ChildGuard {
849 fn drop(&mut self) {
850 let _ = self.0.kill();
851 let _ = self.0.wait();
852 }
853 }
854
855 let ours = resource_usage(std::process::id()).unwrap();
859 let bytes = usize::try_from(ours.memory_bytes)
860 .unwrap()
861 .checked_add(64 * 1024 * 1024)
862 .unwrap();
863 let scratch = cortexkit_test_support::ScratchDir::new("subc-os-resource-usage");
864 let ready = scratch.join("ready");
865 let mut child = ChildGuard(
866 Command::new(std::env::current_exe().unwrap())
867 .args([
868 "tests::resource_usage_child",
869 "--exact",
870 "--ignored",
871 "--nocapture",
872 "--test-threads=1",
873 ])
874 .env("SUBC_OS_TEST_RESOURCE_BYTES", bytes.to_string())
875 .env("SUBC_OS_TEST_RESOURCE_READY", &ready)
876 .stdin(Stdio::piped())
877 .stdout(Stdio::null())
878 .spawn()
879 .unwrap(),
880 );
881 let deadline = Instant::now() + Duration::from_secs(10);
882 while !ready.exists() {
883 assert!(child.0.try_wait().unwrap().is_none(), "memory child exited");
884 assert!(Instant::now() < deadline, "memory child never became ready");
885 std::thread::sleep(Duration::from_millis(5));
886 }
887
888 let ours = resource_usage(std::process::id()).unwrap();
889 let usage = resource_usage(child.0.id()).expect("live child is readable");
890 assert!(
893 ours.memory_bytes < bytes as u64,
894 "caller uses {} bytes, overlapping the child's {bytes} touched bytes",
895 ours.memory_bytes,
896 );
897 assert!(
898 usage.memory_bytes >= bytes as u64,
899 "child uses {} bytes, fewer than its {bytes} touched bytes (caller uses {})",
900 usage.memory_bytes,
901 ours.memory_bytes,
902 );
903 }
904
905 #[test]
906 #[ignore = "re-exec fixture retaining touched private memory until its parent closes stdin"]
907 fn resource_usage_child() {
908 let bytes: usize = std::env::var("SUBC_OS_TEST_RESOURCE_BYTES")
909 .unwrap()
910 .parse()
911 .unwrap();
912 let ready = std::env::var_os("SUBC_OS_TEST_RESOURCE_READY").unwrap();
913 let pages = vec![0xa5u8; bytes];
914 std::hint::black_box(&pages);
915 std::fs::write(ready, b"ready").unwrap();
916 let _ = std::io::stdin().read(&mut [0]);
917 std::hint::black_box(&pages);
918 }
919
920 #[test]
921 fn an_exited_child_reads_as_unavailable_not_zero() {
922 let mut child = spawn_sleep();
923 let pid = child.id();
924 child.kill().unwrap();
925 let deadline = Instant::now() + Duration::from_secs(5);
927 while start_time(pid).is_some() {
928 assert!(Instant::now() < deadline, "child still observed as alive");
929 std::thread::sleep(Duration::from_millis(10));
930 }
931 assert_eq!(resource_usage(pid), None, "a zombie reads as unavailable");
932 child.wait().unwrap();
933 if let Some(usage) = resource_usage(pid) {
936 assert!(usage.memory_bytes > 0, "a reused pid is some live process");
937 }
938 }
939
940 #[test]
941 fn a_pid_with_no_process_reads_as_unavailable() {
942 assert_eq!(resource_usage(i32::MAX as u32), None);
945 assert_eq!(resource_usage(u32::MAX), None);
947 }
948
949 #[cfg(target_os = "linux")]
950 #[test]
951 fn linux_signals_go_through_a_pidfd() {
952 let mut child = spawn_sleep();
953 let process = Process::open(child.id()).unwrap().unwrap();
954 assert!(process.signals_through_pidfd());
955 child.kill().unwrap();
956 child.wait().unwrap();
957 assert!(!process.signal(Signal::Kill).unwrap());
959 }
960}