From bf5ef090c5c5b215672321b67daa753ce00b70c6 Mon Sep 17 00:00:00 2001 From: Qinxuan Chen Date: Sat, 14 Nov 2020 05:00:24 +0800 Subject: [PATCH] Support `/proc/[pid]/task/[tid]/status` (#110) Signed-off-by: koushiro --- src/process/task.rs | 14 +++++++++++--- src/process/tests.rs | 2 ++ src/sys/fs/binfmt_misc.rs | 2 ++ support.md | 2 ++ 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/process/task.rs b/src/process/task.rs index 662e214c..177c71c4 100644 --- a/src/process/task.rs +++ b/src/process/task.rs @@ -1,6 +1,6 @@ use std::path::{Path, PathBuf}; -use super::{FileWrapper, Io, ProcError, Stat}; +use super::{FileWrapper, Io, ProcError, Stat, Status}; use crate::ProcResult; /// A task (aka Thread) inside of a [`Process`](crate::process::Process) @@ -37,6 +37,13 @@ impl Task { Stat::from_reader(FileWrapper::open(self.root.join("stat"))?) } + /// Thread info from `/proc//task//status` + /// + /// Many of the returned fields will be the same as the parent process + pub fn status(&self) -> ProcResult { + Status::from_reader(FileWrapper::open(self.root.join("status"))?) + } + /// Thread IO info from `/proc//task//io` /// /// This data will be unique per task. @@ -117,6 +124,7 @@ mod tests { for task in me.tasks().unwrap() { let task = task.unwrap(); let stat = task.stat().unwrap(); + let status = task.status().unwrap(); let io = task.io().unwrap(); summed_io.rchar += io.rchar; @@ -127,12 +135,12 @@ mod tests { summed_io.write_bytes += io.write_bytes; summed_io.cancelled_write_bytes += io.cancelled_write_bytes; - if stat.comm == "one" { + if stat.comm == "one" && status.name == "one" { found_one = true; assert!(io.rchar >= bytes_to_read); assert!(stat.utime >= 50, "utime({}) too small", stat.utime); } - if stat.comm == "two" { + if stat.comm == "two" && status.name == "two" { found_two = true; assert_eq!(io.rchar, 0); assert_eq!(stat.utime, 0); diff --git a/src/process/tests.rs b/src/process/tests.rs index 65cfabca..9878eed3 100644 --- a/src/process/tests.rs +++ b/src/process/tests.rs @@ -142,6 +142,8 @@ fn test_all() { for task in tasks { let task = task.unwrap(); check_unwrap(&prc, task.stat()); + check_unwrap(&prc, task.status()); + check_unwrap(&prc, task.io()); } } } diff --git a/src/sys/fs/binfmt_misc.rs b/src/sys/fs/binfmt_misc.rs index 54dcfc18..8665dcea 100644 --- a/src/sys/fs/binfmt_misc.rs +++ b/src/sys/fs/binfmt_misc.rs @@ -6,6 +6,7 @@ pub fn enabled() -> ProcResult { Ok(val == "enabled") } +/* struct BinFmtEntry { pub enabled: bool, pub interpreter: String, @@ -13,6 +14,7 @@ struct BinFmtEntry { pub offset: u8, pub magic: Vec, } +*/ #[cfg(test)] mod tests { diff --git a/support.md b/support.md index a49c20cc..d12625e8 100644 --- a/support.md +++ b/support.md @@ -51,6 +51,8 @@ This is an approximate list of all the files under the `/proc` mount, and an ind * [ ] `/proc/[pid]/syscall` * [ ] `/proc/[pid]/task` * [x] `/proc/[pid]/task/[tid]/stat` + * [x] `/proc/[pid]/task/[tid]/status` + * [x] `/proc/[pid]/task/[tid]/io` * [ ] `/proc/[pid]/task/[tid]/children` * [ ] `/proc/[pid]/timers` * [ ] `/proc/[pid]/timerslack_ns`