]>
git.proxmox.com Git - rustc.git/blob - src/test/run-pass/wait-forked-but-failed-child.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
13 use std
::io
::process
::Command
;
15 use libc
::funcs
::posix88
::unistd
;
17 // The output from "ps -A -o pid,ppid,args" should look like this:
24 // 7164 6076 ./spawn-failure
25 // 7165 7164 [spawn-failure] <defunct>
26 // 7166 7164 [spawn-failure] <defunct>
28 // 7197 7164 [spawn-failure] <defunct>
29 // 7198 7164 ps -A -o pid,ppid,command
34 let my_pid
= unsafe { unistd::getpid() }
;
36 // http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ps.html
37 let ps_cmd_output
= Command
::new("ps").args(&["-A", "-o", "pid,ppid,args"]).output().unwrap();
38 let ps_output
= String
::from_utf8_lossy(ps_cmd_output
.output
.as_slice());
40 for (line_no
, line
) in ps_output
.split('
\n'
).enumerate() {
41 if 0 < line_no
&& 0 < line
.len() &&
42 my_pid
== line
.split(' '
).filter(|w
| 0 < w
.len()).nth(1)
43 .expect("1st column should be PPID")
45 .expect("PPID string into integer") &&
46 line
.contains("defunct") {
47 panic
!("Zombie child {}", line
);
56 let too_long
= format
!("/NoSuchCommand{:0300}", 0u8);
58 let _failures
= range(0, 100).map(|_
| {
59 let cmd
= Command
::new(too_long
.as_slice());
60 let failed
= cmd
.spawn();
61 assert
!(failed
.is_err(), "Make sure the command fails to spawn(): {}", cmd
);
63 }).collect
::<Vec
<_
>>();
66 // then _failures goes out of scope