I am using the following to execute a command and then wait to see if it results in a Segmentation Fault. However sometimes the command that gets executed goes in an infinite loop. I need to put a timeout for 5 seconds so that I am not waiting indefinitely.
let mut put_command = Command::new(program_name).stdin(Stdio::piped()).spawn().unwrap();
write!(put_command.stdin.as_mut().unwrap(), "{}", inputtext).unwrap();
let one_sec = Duration::from_secs(1);
let status = put_command.wait().unwrap();
match status.signal() {
Some(signal) if signal == libc::SIGSEGV => {
println!("the process resulted in segmentation fault");
}
_ => (),
}
I tried using wait_timeout as following:
let one_sec = Duration::from_secs(1);
let status = put_command.wait_timeout(one_sec).unwrap();
but I get the following error during compile time:
error[E0599]: no method named `signal` found for enum `Option` in the current scope
--> src/main.rs:72:22
|
72 | match status.signal() {
| ^^^^^^ method not found in `Option<ExitStatus>`
Please advise.