Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/libstd/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ impl Child {
/// }
/// ```
#[stable(feature = "process_id", since = "1.3.0")]
pub fn id(&self) -> u32 {
pub fn id(&self) -> imp::ProcessId {
self.handle.id()
}

Expand Down
21 changes: 19 additions & 2 deletions src/libstd/sys/redox/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// except according to those terms.

use collections::hash_map::HashMap;
use core::ops::Deref;
use env;
use ffi::OsStr;
use fmt;
Expand Down Expand Up @@ -483,15 +484,31 @@ impl fmt::Display for ExitStatus {
}
}

/// Represents a process id.
///
/// Returned by the [Child::id]() method.
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Hash)]
#[stable(feature = "rust1", since = "1.21.0")]
pub struct ProcessId(pub usize);

#[stable(feature = "rust1", since = "1.21.0")]
impl Deref for ProcessId {
type Target = usize;

fn deref(&self) -> &usize {
&self.0
}
}

/// The unique id of the process (this should never be negative).
pub struct Process {
pid: usize,
status: Option<ExitStatus>,
}

impl Process {
pub fn id(&self) -> u32 {
self.pid as u32
pub fn id(&self) -> ProcessId {
ProcessId(self.pid)
}

pub fn kill(&mut self) -> io::Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/sys/unix/process/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// except according to those terms.

pub use self::process_common::{Command, ExitStatus, Stdio, StdioPipes};
pub use self::process_inner::Process;
pub use self::process_inner::{Process, ProcessId};

mod process_common;
#[cfg(not(target_os = "fuchsia"))]
Expand Down
21 changes: 19 additions & 2 deletions src/libstd/sys/unix/process/process_fuchsia.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use libc;
use mem;
use ptr;

use core::ops::Deref;
use sys::process::magenta::{Handle, mx_handle_t};
use sys::process::process_common::*;

Expand Down Expand Up @@ -126,13 +127,29 @@ impl Command {
// Processes
////////////////////////////////////////////////////////////////////////////////

/// Represents a process id.
///
/// Returned by the [Child::id]() method.
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Hash)]
#[stable(feature = "rust1", since = "1.21.0")]
pub struct ProcessId(pub i32);

#[stable(feature = "rust1", since = "1.21.0")]
impl Deref for ProcessId {
type Target = i32;

fn deref(&self) -> &i32 {
&self.0
}
}

pub struct Process {
handle: Handle,
}

impl Process {
pub fn id(&self) -> u32 {
self.handle.raw() as u32
pub fn id(&self) -> ProcessId {
ProcessId(self.handle.raw())
}

pub fn kill(&mut self) -> io::Result<()> {
Expand Down
21 changes: 19 additions & 2 deletions src/libstd/sys/unix/process/process_unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use libc::{self, c_int, gid_t, pid_t, uid_t};
use mem;
use ptr;

use core::ops::Deref;
use sys::cvt;
use sys::process::process_common::*;

Expand Down Expand Up @@ -224,15 +225,31 @@ impl Command {
// Processes
////////////////////////////////////////////////////////////////////////////////

/// Represents a process id.
///
/// Returned by the [Child::id]() method.
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Hash)]
#[stable(feature = "rust1", since = "1.21.0")]
pub struct ProcessId(pub i32);

#[stable(feature = "rust1", since = "1.21.0")]
impl Deref for ProcessId {
type Target = i32;

fn deref(&self) -> &i32 {
&self.0
}
}

/// The unique id of the process (this should never be negative).
pub struct Process {
pid: pid_t,
status: Option<ExitStatus>,
}

impl Process {
pub fn id(&self) -> u32 {
self.pid as u32
pub fn id(&self) -> ProcessId {
ProcessId(self.pid)
}

pub fn kill(&mut self) -> io::Result<()> {
Expand Down
21 changes: 19 additions & 2 deletions src/libstd/sys/windows/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use ascii::*;
use collections::HashMap;
use collections;
use core::ops::Deref;
use env::split_paths;
use env;
use ffi::{OsString, OsStr};
Expand Down Expand Up @@ -322,6 +323,22 @@ impl From<File> for Stdio {
// Processes
////////////////////////////////////////////////////////////////////////////////

/// Represents a process id.
///
/// Returned by the [Child::id]() method.
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Hash)]
#[stable(feature = "rust1", since = "1.21.0")]
pub struct ProcessId(pub u32);

#[stable(feature = "rust1", since = "1.21.0")]
impl Deref for ProcessId {
type Target = u32;

fn deref(&self) -> &u32 {
&self.0
}
}

/// A value representing a child process.
///
/// The lifetime of this value is linked to the lifetime of the actual
Expand All @@ -339,9 +356,9 @@ impl Process {
Ok(())
}

pub fn id(&self) -> u32 {
pub fn id(&self) -> ProcessId {
unsafe {
c::GetProcessId(self.handle.raw()) as u32
ProcessId(c::GetProcessId(self.handle.raw()))
}
}

Expand Down