Created
December 21, 2023 21:08
-
-
Save chadaustin/73e59498f25eba7d4501920e7db29d34 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env rust-script | |
//! ```cargo | |
//! [dependencies] | |
//! anyhow = "1" | |
//! libc = "0.2" | |
//! procfs = "0.16" | |
//! ``` | |
use procfs::process::Process; | |
use std::ffi::OsStr; | |
const INIT_PID: libc::pid_t = 1; | |
#[cfg(target_os = "linux")] | |
fn main() -> anyhow::Result<std::process::ExitCode> { | |
let mosh_server_name: &OsStr = OsStr::new("mosh-server"); | |
let my_ppid = unsafe { libc::getppid() }; | |
let mut p = Process::new(my_ppid)?; | |
while p.pid != INIT_PID { | |
if p.exe()?.file_name() == Some(mosh_server_name) { | |
return Ok(0.into()); | |
} | |
p = Process::new(p.status()?.ppid)?; | |
} | |
return Ok(1.into()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment