Skip to main content

JobObject

Struct JobObject 

pub struct JobObject {
    pid: Option<u32>,
}
Expand description

Process group kill-guard for Unix. The child is spawned in a new session (via setsid()), so it becomes the leader of a new process group. On drop, the entire group is sent SIGKILL, ensuring no orphaned JVM subprocesses.

Fields§

§pid: Option<u32>

Implementations§

§

impl ProcessGroupGuard

pub fn new() -> Result<ProcessGroupGuard, Error>

Create a fresh guard (no child assigned yet).

pub fn configure_command(&self, cmd: &mut Command)

Configure the command to create a new process group / session. Must be called before cmd.spawn().

pub fn assign(&mut self, child: &Child)

Record the child PID so the guard can kill the process group on drop.

pub fn assign_pid(&mut self, pid: u32)

Record a bare PID (the leader of the process group) to kill on drop.

pub fn kill_group(&mut self) -> Result<(), Error>

Kill the process group with SIGKILL. killpg takes a POSITIVE process-group id: the leader’s PID is the group id (the child became group leader via setsid), and a negated id is rejected with EINVAL. ESRCH means the group is already gone — the normal case after a clean exit — so it maps to Ok(()). The pid is taken so the guard is disarmed and a second call, and the Drop, are no-ops.

pub fn release(&mut self) -> Result<(), Error>

Disarm the guard WITHOUT killing: the group outlives the guard.

pub fn is_armed(&self) -> bool

Whether a pid is recorded and the guard can still act.

Trait Implementations§

§

impl Drop for ProcessGroupGuard

§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. 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.