1 use libc::{kill, SIGSTOP}; 2 use rustix::process; 3 use serial_test::serial; 4 use std::process::{Command, Stdio}; 5 6 // These tests must execute serially to prevent race condition, where 7 // `test_wait` waits for the child process spawned in `test_waitpid`, causing 8 // the tests to get stuck. 9 10 #[test] 11 #[serial] test_waitpid()12fn test_waitpid() { 13 let child = Command::new("yes") 14 .stdout(Stdio::null()) 15 .stderr(Stdio::null()) 16 .spawn() 17 .expect("failed to execute child"); 18 unsafe { kill(child.id() as _, SIGSTOP) }; 19 20 let pid = unsafe { process::Pid::from_raw(child.id() as _) }; 21 let status = process::waitpid(pid, process::WaitOptions::UNTRACED) 22 .expect("failed to wait") 23 .unwrap(); 24 assert!(status.stopped()); 25 } 26