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