exepid

Crates.ioexepid
lib.rsexepid
version0.1.3
created_at2025-06-25 07:30:32.66755+00
updated_at2025-06-25 07:45:28.488995+00
descriptionexepid
homepagehttps://github.com/i18n-site/rust/tree/dev/exepid
repositoryhttps://github.com/i18n-site/rust.git
max_upload_size
id1725422
size20,697
i18n.site (i18nsite)

documentation

README

exepid

use std::{env, fs::write, path::Path, process};

pub fn save() -> std::io::Result<()> {
  let pid = process::id();

  let pid_file = if let Ok(fp) = env::var("PID_FILE") {
    fp.into()
  } else {
    let exe_path = env::current_exe()?;
    let exe_folder = exe_path.parent().unwrap_or_else(|| Path::new("."));

    let program_name = exe_path
      .file_stem()
      .and_then(|os_str| os_str.to_str())
      .unwrap_or("");

    exe_folder.join(format!("{}.pid", program_name))
  };

  write(pid_file, pid.to_string())?;

  Ok(())
}

About

This project is an open-source component of i18n.site ⋅ Internationalization Solution.

关于

本项目为 i18n.site ⋅ 国际化解决方案 的开源组件。

Commit count: 68

cargo fmt