2019-07-26 16:54:25 -05:00
|
|
|
// run-pass
|
|
|
|
|
2018-09-14 05:20:28 -05:00
|
|
|
#![allow(stable_features)]
|
2017-10-17 20:45:42 -05:00
|
|
|
// ignore-emscripten no processes
|
2019-04-24 11:26:33 -05:00
|
|
|
// ignore-sgx no processes
|
2017-01-17 01:10:00 -06:00
|
|
|
|
2017-01-06 00:47:09 -06:00
|
|
|
#![feature(process_try_wait)]
|
|
|
|
|
|
|
|
use std::env;
|
|
|
|
use std::process::Command;
|
|
|
|
use std::thread;
|
|
|
|
use std::time::Duration;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let args = env::args().collect::<Vec<_>>();
|
|
|
|
if args.len() != 1 {
|
|
|
|
match &args[1][..] {
|
|
|
|
"sleep" => thread::sleep(Duration::new(1_000, 0)),
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut me = Command::new(env::current_exe().unwrap())
|
|
|
|
.arg("sleep")
|
|
|
|
.spawn()
|
|
|
|
.unwrap();
|
2017-02-03 16:39:41 -06:00
|
|
|
let maybe_status = me.try_wait().unwrap();
|
|
|
|
assert!(maybe_status.is_none());
|
|
|
|
let maybe_status = me.try_wait().unwrap();
|
|
|
|
assert!(maybe_status.is_none());
|
2017-01-06 00:47:09 -06:00
|
|
|
|
|
|
|
me.kill().unwrap();
|
|
|
|
me.wait().unwrap();
|
|
|
|
|
2017-02-03 16:39:41 -06:00
|
|
|
let status = me.try_wait().unwrap().unwrap();
|
2017-01-06 00:47:09 -06:00
|
|
|
assert!(!status.success());
|
2017-02-03 16:39:41 -06:00
|
|
|
let status = me.try_wait().unwrap().unwrap();
|
2017-01-06 00:47:09 -06:00
|
|
|
assert!(!status.success());
|
|
|
|
|
|
|
|
let mut me = Command::new(env::current_exe().unwrap())
|
|
|
|
.arg("return-quickly")
|
|
|
|
.spawn()
|
|
|
|
.unwrap();
|
|
|
|
loop {
|
|
|
|
match me.try_wait() {
|
2017-02-03 16:39:41 -06:00
|
|
|
Ok(Some(res)) => {
|
2017-01-06 00:47:09 -06:00
|
|
|
assert!(res.success());
|
|
|
|
break
|
|
|
|
}
|
2017-02-03 16:39:41 -06:00
|
|
|
Ok(None) => {
|
2017-01-06 00:47:09 -06:00
|
|
|
thread::sleep(Duration::from_millis(1));
|
|
|
|
}
|
|
|
|
Err(e) => panic!("error in try_wait: {}", e),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-03 16:39:41 -06:00
|
|
|
let status = me.try_wait().unwrap().unwrap();
|
2017-01-06 00:47:09 -06:00
|
|
|
assert!(status.success());
|
|
|
|
}
|