Skip to content

Commit

Permalink
Merge pull request #93 from nbaksalyar/proc-task-self
Browse files Browse the repository at this point in the history
Add a method to get a task for main thread
  • Loading branch information
eminence authored Sep 4, 2020
2 parents 57d0140 + cfb44bd commit 0cff26d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/process/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,11 @@ impl Process {
StatM::from_reader(file)
}

/// Return a task for the main thread of this process
pub fn task_main_thread(&self) -> ProcResult<Task> {
Task::from_rel_path(self.pid, Path::new(&format!("{}", self.pid)))
}

/// Iterate over all the [`Task`]s (aka Threads) in this process
///
/// Note that the iterator does not receive a snapshot of tasks, it is a
Expand Down
7 changes: 7 additions & 0 deletions src/process/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ fn check_unwrap<T>(prc: &Process, val: ProcResult<T>) {
}
}

#[test]
fn test_main_thread_task() {
let myself = Process::myself().unwrap();
let task = myself.task_main_thread().unwrap();
check_unwrap(&myself, task.stat());
}

#[allow(clippy::cognitive_complexity)]
#[test]
fn test_self_proc() {
Expand Down

0 comments on commit 0cff26d

Please sign in to comment.