New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
process::Process:name is truncated for Linux #154
Comments
|
@ChristianWitts thank you for a note, it is a good option.
|
gopsutil reads This file is readable by everybody even for processes owned by root. |
@Lomanic brilliant idea! Reading only the first line from one file will be much cheaper comparing to "/stat" -> "readlink" -> "/cmdline" chain |
In fact we fallback to reading |
@Lomanic, ah, okay, |
So I am actually an idiot, and did not notice the use std::{fs, path::Path};
fn cmd_args(filename: impl AsRef<Path>) -> String {
let cmdline: String = fs::read_to_string(filename).expect("no such file")
.parse().expect("Unable to parse file");
cmdline
}
fn main() {
let cmdline = cmd_args("/proc/$PID/cmdline");
// Trim trailing NULL char before splitting into components
let d: Vec<&str> = cmdline.trim_matches('\0').split('\0').collect();
println!("{:?}", d);
} |
Change inspired by heim-rs/heim#154. This was the cause of some process names getting cut off and looking weird for Linux (and Linux only, I'm not directly responsible for the other OSes). This also adds spaces in between command line flags. Before, they were usually separated by either spaces (good) or null terminators (bad).
/proc/{pid}/stat
returns truncated (capped to 15 chars) process name,Process::cmdline
could be used to fetch full process name if necessary.Blocked by #97
The text was updated successfully, but these errors were encountered: