Add process::parent_id

I have this as a Unix-only API since it seems like Windows doesn't have
a similar API.
This commit is contained in:
Steven Fackler 2017-11-18 21:09:18 -08:00
parent 6160040d85
commit 1e42d5f2e1
3 changed files with 14 additions and 0 deletions

View file

@ -213,3 +213,7 @@ pub fn exit(code: i32) -> ! {
pub fn getpid() -> u32 {
syscall::getpid().unwrap() as u32
}
pub fn getppid() -> u32 {
syscall::getppid().unwrap() as u32
}

View file

@ -191,3 +191,9 @@ impl IntoRawFd for process::ChildStderr {
self.into_inner().into_fd().into_raw()
}
}
/// Returns the OS-assigned process identifier associated with this process's parent.
#[unstable(feature = "unix_ppid", issue = "46104")]
pub fn parent_id() -> u32 {
::sys::os::getppid()
}

View file

@ -515,3 +515,7 @@ pub fn exit(code: i32) -> ! {
pub fn getpid() -> u32 {
unsafe { libc::getpid() as u32 }
}
pub fn getppid() -> u32 {
unsafe { libc::getppid() as u32 }
}