Rollup merge of #45059 - tmccombs:pid, r=alexcrichton
Add current_pid function Fixes #44971
This commit is contained in:
commit
bea6136b4a
@ -1310,6 +1310,25 @@ pub fn abort() -> ! {
|
||||
unsafe { ::sys::abort_internal() };
|
||||
}
|
||||
|
||||
/// Returns the OS-assigned process identifier associated with this process.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// Basic usage:
|
||||
///
|
||||
/// ```no_run
|
||||
/// #![feature(getpid)]
|
||||
/// use std::process;
|
||||
///
|
||||
/// println!("My pid is {}", process::id());
|
||||
/// ```
|
||||
///
|
||||
///
|
||||
#[unstable(feature = "getpid", issue = "44971", reason = "recently added")]
|
||||
pub fn id() -> u32 {
|
||||
::sys::os::getpid()
|
||||
}
|
||||
|
||||
#[cfg(all(test, not(target_os = "emscripten")))]
|
||||
mod tests {
|
||||
use io::prelude::*;
|
||||
|
@ -209,3 +209,7 @@ pub fn exit(code: i32) -> ! {
|
||||
let _ = syscall::exit(code as usize);
|
||||
unreachable!();
|
||||
}
|
||||
|
||||
pub fn getpid() -> u32 {
|
||||
syscall::getpid().unwrap() as u32
|
||||
}
|
||||
|
@ -511,3 +511,7 @@ pub fn home_dir() -> Option<PathBuf> {
|
||||
pub fn exit(code: i32) -> ! {
|
||||
unsafe { libc::exit(code as c_int) }
|
||||
}
|
||||
|
||||
pub fn getpid() -> u32 {
|
||||
unsafe { libc::getpid() as u32 }
|
||||
}
|
||||
|
@ -318,6 +318,10 @@ pub fn exit(code: i32) -> ! {
|
||||
unsafe { c::ExitProcess(code as c::UINT) }
|
||||
}
|
||||
|
||||
pub fn getpid() -> u32 {
|
||||
unsafe { c::GetCurrentProcessId() as u32 }
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use io::Error;
|
||||
|
Loading…
x
Reference in New Issue
Block a user