#process #guard #drop #process-running #terminating

process_guard

Guard a process by terminating it on drop

3 unstable releases

Uses old Rust 2015

0.2.0 Jun 21, 2018
0.1.2 Jun 21, 2018
0.1.1 Jun 21, 2018

#14 in #process-running

Download history 3/week @ 2023-11-29 2/week @ 2024-02-14 19/week @ 2024-02-21 31/week @ 2024-02-28 6/week @ 2024-03-06 6/week @ 2024-03-13

64 downloads per month
Used in 2 crates (via pgdb)

MIT license

8KB
78 lines

process_guard

A process guard takes ownership of a process::Child and gently or forcefully kills it upon, prevent the process from running on. Example:

use process_guard::ProcessGuard;
use std::process;

fn insomnia() {
   let cmd = process::Command::new("sleep").arg("120");
   let pg = ProcessGuard::spawn(cmd);

   // a two-minute sleep process has been started, which will be killed as soon as this
   // function returns
}

OS support

The crate is currently only developed with Linux in mind. Windows/BSD/Mac OS X ports are appreciated


lib.rs:

Process guard

A process guard takes ownership of a process::Child and gently or forcefully kills it upon, prevent the process from running on. Example:

use process_guard::ProcessGuard;
use std::process;

fn insomnia() {
    let pg = ProcessGuard::spawn(process::Command::new("sleep").arg("120"));

    // a two-minute sleep process has been started, which will be killed as soon as this
    // function returns
}

Dependencies

~1.5MB
~37K SLoC