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

#279 in Operating systems

Download history 3133/week @ 2024-10-20 3421/week @ 2024-10-27 3539/week @ 2024-11-03 3710/week @ 2024-11-10 2794/week @ 2024-11-17 3140/week @ 2024-11-24 3156/week @ 2024-12-01 3290/week @ 2024-12-08 2774/week @ 2024-12-15 2694/week @ 2024-12-22 2747/week @ 2024-12-29 3778/week @ 2025-01-05 2986/week @ 2025-01-12 2946/week @ 2025-01-19 2913/week @ 2025-01-26 3004/week @ 2025-02-02

12,157 downloads per month
Used in 21 crates (20 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
~60K SLoC