8 releases

Uses old Rust 2015

0.3.3 Dec 16, 2021
0.3.2 Sep 22, 2021
0.3.1 Feb 14, 2021
0.2.0 Feb 13, 2021
0.1.0 Jan 30, 2018

#202 in Operating systems

Download history 2811/week @ 2024-06-20 2570/week @ 2024-06-27 2505/week @ 2024-07-04 3244/week @ 2024-07-11 3272/week @ 2024-07-18 2919/week @ 2024-07-25 3026/week @ 2024-08-01 2504/week @ 2024-08-08 3455/week @ 2024-08-15 3029/week @ 2024-08-22 2820/week @ 2024-08-29 3415/week @ 2024-09-05 2663/week @ 2024-09-12 2858/week @ 2024-09-19 3239/week @ 2024-09-26 3081/week @ 2024-10-03

12,331 downloads per month
Used in 20 crates (19 directly)

MIT license

9KB
156 lines

single-instance

Crates.io Build Status

single-instance provides a single API to check if there are any other running instance.

Detail

On windows, init SingleInstance will create a mutex named by given &str then check error code by calling GetLastError. On linux init will bind abstract unix domain socket with given name . On macos, init will create or open a file which path is given &str, then call flock to apply an advisory lock on the open file.

[dependencies]
single-instance = "0.3"

Examples

extern crate single_instance;

use single_instance::SingleInstance;

fn main() {
    {
        let instance_a = SingleInstance::new("whatever").unwrap();
        assert!(instance_a.is_single());
        let instance_b = SingleInstance::new("whatever").unwrap();
        assert!(!instance_b.is_single());
    }
    let instance_c = SingleInstance::new("whatever").unwrap();
    assert!(instance_c.is_single());
}

Dependencies

~3MB
~62K SLoC