[−][src]Struct procfs::process::Process
Represents a process in /proc/<pid>
.
The stat
structure is pre-populated because it's useful info, but other data is loaded on
demand (and so might fail, if the process no longer exist).
Fields
pid: i32
The process ID
(same as the Stat.pid
field).
stat: Stat
Process status, based on the /proc/<pid>/stat
file.
owner: u32
The user id of the owner of this process
Implementations
impl Process
[src]
pub fn limits(&self) -> ProcResult<Limits>
[src]
Return the limits for this process
impl Process
[src]
pub fn mountstats(&self) -> ProcResult<Vec<MountStat>>
[src]
Returns the MountStat data for this processes mount namespace.
pub fn mountinfo(&self) -> ProcResult<Vec<MountInfo>>
[src]
Returns info about the mountpoints in this this process's mount namespace
This data is taken from the /proc/[pid]/mountinfo
file
(Since Linux 2.6.26)
impl Process
[src]
pub fn new(pid: pid_t) -> ProcResult<Process>
[src]
Returns a Process
based on a specified PID.
This can fail if the process doesn't exist, or if you don't have permission to access it.
pub fn new_with_root(root: PathBuf) -> ProcResult<Process>
[src]
Returns a Process
based on a specified /proc/<pid>
path.
pub fn myself() -> ProcResult<Process>
[src]
Returns a Process
for the currently running process.
This is done by using the /proc/self
symlink
pub fn cmdline(&self) -> ProcResult<Vec<String>>
[src]
Returns the complete command line for the process, unless the process is a zombie.
pub fn pid(&self) -> pid_t
[src]
Returns the process ID for this process.
pub fn is_alive(&self) -> bool
[src]
Is this process still alive?
pub fn cwd(&self) -> ProcResult<PathBuf>
[src]
Retrieves current working directory of the process by dereferencing /proc/<pid>/cwd
symbolic link.
This method has the following caveats:
-
if the pathname has been unlinked, the symbolic link will contain the string " (deleted)" appended to the original pathname
-
in a multithreaded process, the contents of this symbolic link are not available if the main thread has already terminated (typically by calling
pthread_exit(3)
) -
permission to dereference or read this symbolic link is governed by a
ptrace(2)
access modePTRACE_MODE_READ_FSCREDS
check
pub fn root(&self) -> ProcResult<PathBuf>
[src]
Retrieves current root directory of the process by dereferencing /proc/<pid>/root
symbolic link.
This method has the following caveats:
-
if the pathname has been unlinked, the symbolic link will contain the string " (deleted)" appended to the original pathname
-
in a multithreaded process, the contents of this symbolic link are not available if the main thread has already terminated (typically by calling
pthread_exit(3)
) -
permission to dereference or read this symbolic link is governed by a
ptrace(2)
access modePTRACE_MODE_READ_FSCREDS
check
pub fn environ(&self) -> ProcResult<HashMap<OsString, OsString>>
[src]
Gets the current environment for the process. This is done by reading the
/proc/pid/environ
file.
pub fn exe(&self) -> ProcResult<PathBuf>
[src]
Retrieves the actual path of the executed command by dereferencing /proc/<pid>/exe
symbolic link.
This method has the following caveats:
-
if the pathname has been unlinked, the symbolic link will contain the string " (deleted)" appended to the original pathname
-
in a multithreaded process, the contents of this symbolic link are not available if the main thread has already terminated (typically by calling
pthread_exit(3)
) -
permission to dereference or read this symbolic link is governed by a
ptrace(2)
access modePTRACE_MODE_READ_FSCREDS
check
pub fn io(&self) -> ProcResult<Io>
[src]
Return the Io stats for this process, based on the /proc/pid/io
file.
(since kernel 2.6.20)
pub fn maps(&self) -> ProcResult<Vec<MemoryMap>>
[src]
Return a list of the currently mapped memory regions and their access permissions, based on
the /proc/pid/maps
file.
pub fn fd(&self) -> ProcResult<Vec<FDInfo>>
[src]
Gets a list of open file descriptors for a process
pub fn coredump_filter(&self) -> ProcResult<Option<CoredumpFlags>>
[src]
Lists which memory segments are written to the core dump in the event that a core dump is performed.
By default, the following bits are set: 0, 1, 4 (if the CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS kernel configuration option is enabled), and 5. This default can be modified at boot time using the core dump_filter boot option.
This function will return Err(ProcError::NotFound)
if the coredump_filter
file can't be
found. If it returns Ok(None)
then the process has no coredump_filter
pub fn autogroup(&self) -> ProcResult<String>
[src]
Gets the process's autogroup membership
(since Linux 2.6.38 and requires CONFIG_SCHED_AUTOGROUP)
pub fn auxv(&self) -> ProcResult<HashMap<u32, u32>>
[src]
Get the process's auxiliary vector
(since 2.6.0-test7)
pub fn wchan(&self) -> ProcResult<String>
[src]
Gets the symbolic name corresponding to the location in the kernel where the process is sleeping.
(since Linux 2.6.0)
pub fn status(&self) -> ProcResult<Status>
[src]
Return the Status
for this process, based on the /proc/[pid]/status
file.
pub fn stat(&self) -> ProcResult<Stat>
[src]
Returns the status info from /proc/[pid]/stat
.
Note that this data comes pre-loaded in the stat
field. This method is useful when you
get the latest status data (since some of it changes while the program is running)
pub fn loginuid(&self) -> ProcResult<u32>
[src]
Gets the process' login uid. May not be available.
pub fn oom_score(&self) -> ProcResult<u32>
[src]
The current score that the kernel gives to this process for the purpose of selecting a process for the OOM-killer
A higher score means that the process is more likely to be selected by the OOM-killer. The basis for this score is the amount of memory used by the process, plus other factors.
(Since linux 2.6.11)
pub fn statm(&self) -> ProcResult<StatM>
[src]
Set process memory information
Much of this data is the same as the data from stat()
and status()
pub fn tasks(&self) -> ProcResult<TasksIter>
[src]
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 lazy iterator over whatever happens to be running when the iterator gets there, see the examples below.
Examples
Simple iteration over subtasks
If you want to get the info that most closely matches what was running
when you call tasks
you should collect them as quikcly as possible,
and then run processing over that collection:
let name = "testing:example"; let t = thread::Builder::new().name(name.to_string()) .spawn(move || { // do work })?; let proc = Process::myself()?; // Collect a snapshot let threads: Vec<_> = proc.tasks()?.flatten().map(|t| t.stat().unwrap().comm).collect(); threads.iter().find(|s| &**s == name).expect("thread should exist");
The TaskIterator is lazy
This means both that tasks that stop before you get to them in iteration will not be there, and that new tasks that are created after you start the iterator will appear.
let proc = Process::myself()?; // Task iteration is lazy let mut task_iter = proc.tasks()?.flatten().map(|t| t.stat().unwrap().comm); let name = "testing:lazy"; let t = thread::Builder::new().name(name.to_string()) .spawn(move || { // do work })?; task_iter.find(|s| &**s == name).expect("thread should exist");
Tasks that stop while you're iterating may or may not appear:
let name = "testing:stopped"; let t = thread::Builder::new().name(name.to_string()) .spawn(move || { // do work })?; let proc = Process::myself()?; // Task iteration is lazy let mut task_iter = proc.tasks()?.flatten().map(|t| t.stat().unwrap().comm); t.join().unwrap(); // It's impossible to know if this is going to be gone let _ = task_iter.find(|s| &**s == name).is_some();
impl Process
[src]
pub fn cgroups(&self) -> ProcResult<Vec<ProcessCgroup>>
[src]
Describes control groups to which the process with the corresponding PID belongs.
The displayed information differs for cgroupsversion 1 and version 2 hierarchies.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Process
impl Send for Process
impl Sync for Process
impl Unpin for Process
impl UnwindSafe for Process
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,