about summary refs log tree commit diff
path: root/src/libstd/sys
diff options
context:
space:
mode:
authorThayne McCombs <astrothayne@gmail.com>2017-10-05 23:49:36 -0600
committerThayne McCombs <astrothayne@gmail.com>2017-10-06 01:15:49 -0600
commit6ff6b935608f7c5b6b53517f3fc5bafec911a79d (patch)
treeb0312b09d1013b9c73aa0011a339f1201569c52c /src/libstd/sys
parenta4af9309d060b76ddaeb91c52d9f0e05dc97264c (diff)
downloadrust-6ff6b935608f7c5b6b53517f3fc5bafec911a79d.tar.gz
rust-6ff6b935608f7c5b6b53517f3fc5bafec911a79d.zip
Add current_pid function
Fixes #44971
Diffstat (limited to 'src/libstd/sys')
-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
3 files changed, 12 insertions, 0 deletions
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 5ef98d24710..132f59b999d 100644
--- a/src/libstd/sys/unix/os.rs
+++ b/src/libstd/sys/unix/os.rs
@@ -513,3 +513,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;