Pidfile single process instance mechanism
I don't know much about file locking, but I can guide you in Rust.

I'd suggest changing your write_pid to use writeln!. I think you can simplify it to this.

fn write_pid(mut file: &amp;File) -&gt; Result&lt;(), io::Error&gt; {
    writeln!(file, "{}", process::id())
}


I'd also prefer to reduce the nesting in exclusive, perhaps something like this:

pub fn exclusive(pidfile: &amp;path::Path) -&gt; Result&lt;bool, io::Error&gt; {
    let pf = OpenOptions::new()
        .write(true)
        .create_new(true)
        .open(pidfile);

    match pf {
        Ok(file) =&gt; {
            lock_pidfile(&amp;file, pidfile)?;
            write_pid(&amp;file)?;
            return Ok(true);
        }
        Err(ref e) if e.kind() == ErrorKind::AlreadyExists =&gt; {}
        Err(e) =&gt; return Err(e),
    }

    let mut file = OpenOptions::new().read(true).write(true).open(pidfile)?;
    lock_pidfile(&amp;file, pidfile)?;
    let mut id_str = String::new();
    file.read_to_string(&amp;mut id_str)?;
    let id: u32 = id_str.trim().parse().map_err(|_| {
        Error::new(
            ErrorKind::Other,
            format!("Failed to parse pidfile: {}", pidfile.display()),
        )
    })?;
    // Kill None just checks if process exists.
    // Same as kill(pid, 0); in C
    if kill(Pid::from_raw(id as i32), None).is_ok() {
        Ok(false)
    } else {
        file.seek(SeekFrom::Start(0))?;
        write_pid(&amp;file)?;
        Ok(true)
    }
}