Skip to content

Commit

Permalink
feat: create task by specify pid and tid
Browse files Browse the repository at this point in the history
  • Loading branch information
pearzl committed Jun 7, 2021
1 parent 30ab949 commit e276c30
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/process/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,7 @@ impl Process {

/// 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)))
Task::new(self.pid, self.pid)
}

/// Return the `Schedstat` for this process, based on the `/proc/<pid>/schedstat` file.
Expand Down
12 changes: 12 additions & 0 deletions src/process/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ pub struct Task {
}

impl Task {
/// Create a new `Task`
pub fn new(pid: i32, tid: i32) -> Result<Task, ProcError> {
let root = PathBuf::from(format!("/proc/{}/task/{}", pid, tid));
if root.exists() {
Ok(Task{
pid, tid, root
})
} else {
Err(ProcError::NotFound(Some(root)))
}
}

/// Create a new `Task` inside of the process
///
/// This API is designed to be ergonomic from inside of [`TasksIter`](super::TasksIter)
Expand Down

0 comments on commit e276c30

Please sign in to comment.