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

#223 in Operating systems

Download history 2758/week @ 2024-08-02 2690/week @ 2024-08-09 3348/week @ 2024-08-16 3246/week @ 2024-08-23 2737/week @ 2024-08-30 3267/week @ 2024-09-06 2481/week @ 2024-09-13 3190/week @ 2024-09-20 3225/week @ 2024-09-27 3671/week @ 2024-10-04 3434/week @ 2024-10-11 3507/week @ 2024-10-18 3441/week @ 2024-10-25 3262/week @ 2024-11-01 3747/week @ 2024-11-08 3049/week @ 2024-11-15

13,957 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
~61K SLoC