2019-07-26 21:54:25 +00:00
|
|
|
//@ run-pass
|
|
|
|
|
2018-09-14 10:20:28 +00:00
|
|
|
#![allow(stable_features)]
|
2024-03-06 20:44:54 +00:00
|
|
|
//@ ignore-wasm32 no processes
|
2019-04-24 16:26:33 +00:00
|
|
|
//@ ignore-sgx no processes
|
2017-01-06 06:47:09 +00: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 22:39:41 +00: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 06:47:09 +00:00
|
|
|
|
|
|
|
me.kill().unwrap();
|
|
|
|
me.wait().unwrap();
|
|
|
|
|
2017-02-03 22:39:41 +00:00
|
|
|
let status = me.try_wait().unwrap().unwrap();
|
2017-01-06 06:47:09 +00:00
|
|
|
assert!(!status.success());
|
2017-02-03 22:39:41 +00:00
|
|
|
let status = me.try_wait().unwrap().unwrap();
|
2017-01-06 06:47:09 +00: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 22:39:41 +00:00
|
|
|
Ok(Some(res)) => {
|
2017-01-06 06:47:09 +00:00
|
|
|
assert!(res.success());
|
|
|
|
break
|
|
|
|
}
|
2017-02-03 22:39:41 +00:00
|
|
|
Ok(None) => {
|
2017-01-06 06:47:09 +00:00
|
|
|
thread::sleep(Duration::from_millis(1));
|
|
|
|
}
|
|
|
|
Err(e) => panic!("error in try_wait: {}", e),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-03 22:39:41 +00:00
|
|
|
let status = me.try_wait().unwrap().unwrap();
|
2017-01-06 06:47:09 +00:00
|
|
|
assert!(status.success());
|
|
|
|
}
|