Skip to content

Commit

Permalink
process::Process::suspend and ::resume for nix systems (closes #164)
Browse files Browse the repository at this point in the history
  • Loading branch information
svartalf committed Sep 10, 2019
1 parent 03018e8 commit e62ac98
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
28 changes: 28 additions & 0 deletions heim-process/src/process/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,34 @@ impl Process {
self.as_ref().is_running()
}

/// Suspend the current process.
///
/// Before the signal send, it checks whether process PID has been reused,
/// and if it is a case, [`NoSuchProcess`] error will be returned.
///
/// ## Compatibility
///
/// For *nix systems it sends the `SIGSTOP` signal to process.
///
/// [`NoSuchProcess`]: ./enum.ProcessError.html#variant.NoSuchProcess
pub fn suspend(&self) -> impl Future<Output = ProcessResult<()>> {
self.0.suspend()
}

/// Resume the current process.
///
/// Before the signal send, it checks whether process PID has been reused,
/// and if it is a case, [`NoSuchProcess`] error will be returned.
///
/// ## Compatibility
///
/// For *nix systems it sends the `SIGCONT` signal to process.
///
/// [`NoSuchProcess`]: ./enum.ProcessError.html#variant.NoSuchProcess
pub fn resume(&self) -> impl Future<Output = ProcessResult<()>> {
self.0.resume()
}

/// Terminate the current process.
///
/// Before the signal send, it checks whether process PID has been reused,
Expand Down
8 changes: 8 additions & 0 deletions heim-process/src/sys/linux/process/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ impl Process {
self._signal(signal).boxed()
}

pub fn suspend(&self) -> impl Future<Output = ProcessResult<()>> {
self._signal(Signal::Stop)
}

pub fn resume(&self) -> impl Future<Output = ProcessResult<()>> {
self._signal(Signal::Cont)
}

pub fn terminate(&self) -> impl Future<Output = ProcessResult<()>> {
self._signal(Signal::Term)
}
Expand Down
8 changes: 8 additions & 0 deletions heim-process/src/sys/macos/process/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@ impl Process {
self._signal(signal).boxed()
}

pub fn suspend(&self) -> impl Future<Output = ProcessResult<()>> {
self._signal(Signal::Stop)
}

pub fn resume(&self) -> impl Future<Output = ProcessResult<()>> {
self._signal(Signal::Cont)
}

pub fn terminate(&self) -> impl Future<Output = ProcessResult<()>> {
self._signal(Signal::Term)
}
Expand Down
12 changes: 12 additions & 0 deletions heim-process/src/sys/windows/process/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,18 @@ impl Process {
})
}

pub fn suspend(&self) -> impl Future<Output = ProcessResult<()>> {
future::lazy(|_| {
unimplemented!()
})
}

pub fn resume(&self) -> impl Future<Output = ProcessResult<()>> {
future::lazy(|_| {
unimplemented!()
})
}

pub fn terminate(&self) -> impl Future<Output = ProcessResult<()>> {
self.kill()
}
Expand Down

0 comments on commit e62ac98

Please sign in to comment.