Process

Struct Process 

Source
pub struct Process { /* private fields */ }
Expand description

A process.

Implementations§

Source§

impl Process

Source

pub fn pid(&self) -> Pid

The Process ID.

Source

pub fn is_init(self: &Arc<Self>) -> bool

Returns true if the Process is the init process.

This is a convenience method for checking if the Process Arc::ptr_eqs with the init process, which is cheaper than calling init_proc or testing if Process::parent is None.

Source§

impl Process

Parent & children

Source

pub fn parent(&self) -> Option<Arc<Process>>

The parent Process.

Source

pub fn children(&self) -> Vec<Arc<Process>>

The child Processes.

Source§

impl Process

Source

pub fn group(&self) -> Arc<ProcessGroup>

The ProcessGroup that the Process belongs to.

Source

pub fn create_session( self: &Arc<Self>, ) -> Option<(Arc<Session>, Arc<ProcessGroup>)>

Creates a new Session and new ProcessGroup and moves the Process to it.

If the Process is already a session leader, this method does nothing and returns None.

Otherwise, it returns the new Session and ProcessGroup.

The caller has to ensure that the new ProcessGroup does not conflict with any existing ProcessGroup. Thus, the Process must not be a ProcessGroup leader.

Checking Session conflicts is unnecessary.

Source

pub fn create_group(self: &Arc<Self>) -> Option<Arc<ProcessGroup>>

Creates a new ProcessGroup and moves the Process to it.

If the Process is already a group leader, this method does nothing and returns None.

Otherwise, it returns the new ProcessGroup.

The caller has to ensure that the new ProcessGroup does not conflict with any existing ProcessGroup.

Source

pub fn move_to_group(self: &Arc<Self>, group: &Arc<ProcessGroup>) -> bool

Moves the Process to a specified ProcessGroup.

Returns true if the move succeeded. The move failed if the ProcessGroup is not in the same Session as the Process.

If the Process is already in the specified ProcessGroup, this method does nothing and returns true.

Source§

impl Process

Threads

Source

pub fn add_thread(self: &Arc<Self>, tid: Pid)

Adds a thread to this Process with the given thread ID.

Source

pub fn exit_thread(self: &Arc<Self>, tid: Pid, exit_code: i32) -> bool

Removes a thread from this Process and sets the exit code if the group has not exited.

Returns true if this was the last thread in the process.

Source

pub fn threads(&self) -> Vec<Pid>

Get all threads in this Process.

Source

pub fn is_group_exited(&self) -> bool

Returns true if the Process is group exited.

Source

pub fn group_exit(&self)

Marks the Process as group exited.

Source

pub fn exit_code(&self) -> i32

The exit code of the Process.

Source§

impl Process

Status & exit

Source

pub fn is_zombie(&self) -> bool

Returns true if the Process is a zombie process.

Source

pub fn exit(self: &Arc<Self>)

Terminates the Process, marking it as a zombie process.

Child processes are inherited by the init process or by the nearest subreaper process.

This method panics if the Process is the init process.

Source

pub fn free(&self)

Frees a zombie Process. Removes it from the parent.

This method panics if the Process is not a zombie.

Source§

impl Process

Builder

Source

pub fn new_init(pid: Pid) -> Arc<Process>

Creates a init Process.

This function can be called multiple times, but [ProcessBuilder::build] on the the result must be called only once.

Source

pub fn fork(self: &Arc<Process>, pid: Pid) -> Arc<Process>

Creates a child Process.

Trait Implementations§

Source§

impl Debug for Process

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.