2 // ignore-emscripten no processes
3 // ignore-sgx no processes
4 // ignore-vxworks no 'ps'
6 #![feature(rustc_private)]
10 use std::process::Command;
12 // The output from "ps -A -o pid,ppid,args" should look like this:
19 // 7164 6076 ./spawn-failure
20 // 7165 7164 [spawn-failure] <defunct>
21 // 7166 7164 [spawn-failure] <defunct>
23 // 7197 7164 [spawn-failure] <defunct>
24 // 7198 7164 ps -A -o pid,ppid,command
29 let my_pid = unsafe { libc::getpid() };
31 // https://pubs.opengroup.org/onlinepubs/9699919799/utilities/ps.html
32 let ps_cmd_output = Command::new("ps").args(&["-A", "-o", "pid,ppid,args"]).output().unwrap();
33 let ps_output = String::from_utf8_lossy(&ps_cmd_output.stdout);
35 for (line_no, line) in ps_output.split('\n').enumerate() {
36 if 0 < line_no && 0 < line.len() &&
37 my_pid == line.split(' ').filter(|w| 0 < w.len()).nth(1)
38 .expect("1st column should be PPID")
40 .expect("PPID string into integer") &&
41 line.contains("defunct") {
42 panic!("Zombie child {}", line);
51 let too_long = format!("/NoSuchCommand{:0300}", 0u8);
53 let _failures = (0..100).map(|_| {
54 let mut cmd = Command::new(&too_long);
55 let failed = cmd.spawn();
56 assert!(failed.is_err(), "Make sure the command fails to spawn(): {:?}", cmd);
58 }).collect::<Vec<_>>();
61 // then _failures goes out of scope