about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2017-10-25 22:21:44 +0000
committerbors <bors@rust-lang.org>2017-10-25 22:21:44 +0000
commite847f30f571e617990f7193665ab10127100e9df (patch)
treea2a8f24bd05e4c97879826ee4454cdb3bfc92461 /src/libstd
parentf9d24165948a926263444bfe763f9861cb683246 (diff)
parent851d1c736571b38e68001023167199225377e3b9 (diff)
downloadrust-e847f30f571e617990f7193665ab10127100e9df.tar.gz
rust-e847f30f571e617990f7193665ab10127100e9df.zip
Auto merge of #45532 - kennytm:rollup, r=kennytm
Rollup of 7 pull requests

- Successful merges: #45059, #45212, #45398, #45483, #45496, #45508, #45526
- Failed merges:
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/process.rs19
-rw-r--r--src/libstd/sys/redox/os.rs4
-rw-r--r--src/libstd/sys/unix/os.rs4
-rw-r--r--src/libstd/sys/windows/os.rs4
4 files changed, 31 insertions, 0 deletions
diff --git a/src/libstd/process.rs b/src/libstd/process.rs
index 7c107177c64..c19ece6a314 100644
--- a/src/libstd/process.rs
+++ b/src/libstd/process.rs
@@ -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::*;
diff --git a/src/libstd/sys/redox/os.rs b/src/libstd/sys/redox/os.rs
index efddd5f0294..c27e2ee172c 100644
--- a/src/libstd/sys/redox/os.rs
+++ b/src/libstd/sys/redox/os.rs
@@ -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
+}
diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs
index d8c30534eed..40b73f1b307 100644
--- a/src/libstd/sys/unix/os.rs
+++ b/src/libstd/sys/unix/os.rs
@@ -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 }
+}
diff --git a/src/libstd/sys/windows/os.rs b/src/libstd/sys/windows/os.rs
index a51b458451e..b9448243559 100644
--- a/src/libstd/sys/windows/os.rs
+++ b/src/libstd/sys/windows/os.rs
@@ -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;